/* Copyright 2019 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package framework_test import ( "errors" "os" "path" "testing" "github.com/onsi/ginkgo/v2" "github.com/onsi/ginkgo/v2/reporters" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "k8s.io/klog/v2" "k8s.io/kubernetes/test/e2e/framework" "k8s.io/kubernetes/test/e2e/framework/internal/output" ) // The line number of the following code is checked in TestFailureOutput below. // Be careful when moving it around or changing the import statements above. // Here are some intentionally blank lines that can be removed to compensate // for future additional import statements. // // This must be line #39. // This is included in a stack backtrace. func failHelper(msg string) { framework.Fail(msg) } var _ = ginkgo.Describe("log", func() { ginkgo.BeforeEach(func() { framework.Logf("before") }) ginkgo.AfterEach(func() { framework.Logf("after") framework.ExpectEqual(true, false, "true is never false either") }) ginkgo.It("fails", func() { func() { framework.Failf("I'm failing.") }() }) ginkgo.It("asserts", func() { framework.ExpectEqual(false, true, "false is never true") }) ginkgo.It("error", func() { err := errors.New("an error with a long, useless description") framework.ExpectNoError(err, "hard-coded error") }) ginkgo.It("equal", func() { framework.ExpectEqual(0, 1, "of course it's not equal...") }) ginkgo.It("fails with helper", func() { failHelper("I'm failing with helper.") }) ginkgo.It("redirects klog", func() { klog.Info("hello world") klog.Error(nil, "not really an error") }) }) func TestFailureOutput(t *testing.T) { expected := output.TestResult{ Suite: reporters.JUnitTestSuite{ Tests: 6, Failures: 6, Errors: 0, Disabled: 0, Skipped: 0, TestCases: []reporters.JUnitTestCase{ { Name: "[It] log fails", Status: "failed", Failure: &reporters.JUnitFailure{ Type: "failed", Description: `[FAILED] I'm failing. In [It] at: log_test.go:57