//go:build linux && amd64 /* Copyright 2022 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. */ // This test uses etcd that is only fully supported for AMD64 and Linux // https://etcd.io/docs/v3.5/op-guide/supported-platform/#support-tiers package cleanup import ( "context" "flag" "fmt" "regexp" "testing" "github.com/onsi/ginkgo/v2" "github.com/onsi/ginkgo/v2/reporters" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/klog/v2" "k8s.io/klog/v2/ktesting" "k8s.io/kubernetes/test/e2e/framework" "k8s.io/kubernetes/test/e2e/framework/internal/output" testapiserver "k8s.io/kubernetes/test/utils/apiserver" ) // 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 #50. func init() { framework.NewFrameworkExtensions = append(framework.NewFrameworkExtensions, // This callback runs directly after NewDefaultFramework is done. func(f *framework.Framework) { ginkgo.BeforeEach(func() { framework.Logf("extension before") }) ginkgo.AfterEach(func() { framework.Logf("extension after") }) }, ) } var _ = ginkgo.Describe("e2e", func() { ginkgo.BeforeEach(func() { logBeforeHelper() }) f := framework.NewDefaultFramework("test-namespace") // BeforeEach/AfterEach run in first-in-first-out order. ginkgo.BeforeEach(func() { framework.Logf("before #1") }) ginkgo.BeforeEach(func() { framework.Logf("before #2") }) ginkgo.AfterEach(func() { framework.Logf("after #1") if f.ClientSet == nil { framework.Fail("Wrong order of cleanup operations: framework.AfterEach already ran and cleared f.ClientSet.") } }) ginkgo.AfterEach(func() { framework.Logf("after #2") }) ginkgo.It("works", func(ctx context.Context) { // DeferCleanup invokes in first-in-last-out order ginkgo.DeferCleanup(func() { framework.Logf("cleanup last") }) ginkgo.DeferCleanup(func() { framework.Logf("cleanup first") }) ginkgo.DeferCleanup(framework.IgnoreNotFound(f.ClientSet.CoreV1().PersistentVolumes().Delete), "simple", metav1.DeleteOptions{}) fail := func(ctx context.Context, name string) error { return fmt.Errorf("fake error for %q", name) } ginkgo.DeferCleanup(framework.IgnoreNotFound(fail), "failure") // Without a failure the output would not be shown in JUnit. // More test cases can be added here without affeccting line numbering // of existing tests. }) }) // logBeforeHelper must be skipped when doing stack unwinding in the logging // implementation. func logBeforeHelper() { ginkgo.GinkgoHelper() framework.Logf("before") } const ( ginkgoOutput = `> Enter [BeforeEach] e2e - cleanup_test.go:63