From 9bade48455e4bb157c8fcf30c0865dd18c7e88ac Mon Sep 17 00:00:00 2001 From: zirain Date: Thu, 29 May 2025 07:33:05 +0800 Subject: [PATCH] e2e: use ConformanceOptions.Hook Signed-off-by: zirain --- test/conformance/conformance_test.go | 2 ++ .../experimental_conformance_test.go | 2 ++ test/e2e/e2e_test.go | 1 + test/e2e/hook.go | 22 +++++++++++++++++++ test/e2e/multiple_gc/multiple_gc_test.go | 2 ++ test/e2e/tests/eg_upgrade.go | 5 ----- test/e2e/tests/envoyproxy_daemonset.go | 6 ----- ...httproute_with_dynamic_resolver_backend.go | 10 --------- test/e2e/upgrade/eg_upgrade_test.go | 1 + 9 files changed, 30 insertions(+), 21 deletions(-) create mode 100644 test/e2e/hook.go diff --git a/test/conformance/conformance_test.go b/test/conformance/conformance_test.go index 99b0494562..64a7ba6dde 100644 --- a/test/conformance/conformance_test.go +++ b/test/conformance/conformance_test.go @@ -21,6 +21,7 @@ import ( "sigs.k8s.io/gateway-api/conformance/utils/tlog" internalconf "github.com/envoyproxy/gateway/internal/gatewayapi/conformance" + "github.com/envoyproxy/gateway/test/e2e" ege2etest "github.com/envoyproxy/gateway/test/e2e/tests" ) @@ -44,6 +45,7 @@ func TestGatewayAPIConformance(t *testing.T) { opts.SupportedFeatures = internalSuite.SupportedFeatures opts.ExemptFeatures = internalSuite.ExemptFeatures opts.RunTest = *flags.RunTest + opts.Hook = e2e.Hook cSuite, err := suite.NewConformanceTestSuite(opts) if err != nil { diff --git a/test/conformance/experimental_conformance_test.go b/test/conformance/experimental_conformance_test.go index 1d25ad0b74..0d87cef582 100644 --- a/test/conformance/experimental_conformance_test.go +++ b/test/conformance/experimental_conformance_test.go @@ -24,6 +24,7 @@ import ( "sigs.k8s.io/yaml" internalconf "github.com/envoyproxy/gateway/internal/gatewayapi/conformance" + "github.com/envoyproxy/gateway/test/e2e" ) func TestExperimentalConformance(t *testing.T) { @@ -42,6 +43,7 @@ func TestExperimentalConformance(t *testing.T) { suite.GatewayTLSConformanceProfileName, suite.GatewayGRPCConformanceProfileName, ) + opts.Hook = e2e.Hook t.Logf("Running experimental conformance tests with %s GatewayClass\n cleanup: %t\n debug: %t\n enable all features: %t \n conformance profiles: [%v]", *flags.GatewayClassName, *flags.CleanupBaseResources, *flags.ShowDebug, *flags.EnableAllSupportedFeatures, opts.ConformanceProfiles) diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index a5b9f7c98a..b46a6a5101 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -84,6 +84,7 @@ func TestE2E(t *testing.T) { SupportedFeatures: sets.New(features.SupportGateway), SkipTests: skipTests, AllowCRDsMismatch: *flags.AllowCRDsMismatch, + Hook: Hook, }) if err != nil { t.Fatalf("Failed to create ConformanceTestSuite: %v", err) diff --git a/test/e2e/hook.go b/test/e2e/hook.go new file mode 100644 index 0000000000..db3d644452 --- /dev/null +++ b/test/e2e/hook.go @@ -0,0 +1,22 @@ +// Copyright Envoy Gateway Authors +// SPDX-License-Identifier: Apache-2.0 +// The full text of the Apache license is available in the LICENSE file at +// the root of the repo. + +package e2e + +import ( + "testing" + + "sigs.k8s.io/gateway-api/conformance/utils/suite" + "sigs.k8s.io/gateway-api/conformance/utils/tlog" + + "github.com/envoyproxy/gateway/test/e2e/tests" +) + +var Hook = func(t *testing.T, test suite.ConformanceTest, suite *suite.ConformanceTestSuite) { + if t.Failed() { + tlog.Logf(t, "Test %s failed, collecting and dumping resources", test.ShortName) + tests.CollectAndDump(t, suite.RestConfig) + } +} diff --git a/test/e2e/multiple_gc/multiple_gc_test.go b/test/e2e/multiple_gc/multiple_gc_test.go index 700ed86e03..22d6f8033c 100644 --- a/test/e2e/multiple_gc/multiple_gc_test.go +++ b/test/e2e/multiple_gc/multiple_gc_test.go @@ -50,6 +50,7 @@ func TestMultipleGC(t *testing.T) { // All e2e tests should leave Features empty. SupportedFeatures: sets.New[features.FeatureName](features.SupportGateway), SkipTests: []string{}, + Hook: e2e.Hook, }) if err != nil { t.Fatalf("Failed to create ConformanceTestSuite: %v", err) @@ -83,6 +84,7 @@ func TestMultipleGC(t *testing.T) { // All e2e tests should leave Features empty. SupportedFeatures: sets.New[features.FeatureName](features.SupportGateway), SkipTests: []string{}, + Hook: e2e.Hook, }) if err != nil { t.Fatalf("Failed to create ConformanceTestSuite: %v", err) diff --git a/test/e2e/tests/eg_upgrade.go b/test/e2e/tests/eg_upgrade.go index caeef82689..5a1e494259 100644 --- a/test/e2e/tests/eg_upgrade.go +++ b/test/e2e/tests/eg_upgrade.go @@ -168,11 +168,6 @@ var EGUpgradeTest = suite.ConformanceTest{ t.Errorf("failed to get expected response for the first three requests: %v", err) } }) - t.Cleanup(func() { - if t.Failed() { - CollectAndDump(t, suite.RestConfig) - } - }) }, } diff --git a/test/e2e/tests/envoyproxy_daemonset.go b/test/e2e/tests/envoyproxy_daemonset.go index d3ee87d614..5b7861e57c 100644 --- a/test/e2e/tests/envoyproxy_daemonset.go +++ b/test/e2e/tests/envoyproxy_daemonset.go @@ -35,12 +35,6 @@ var EnvoyProxyDaemonSetTest = suite.ConformanceTest{ Manifests: []string{"testdata/envoyproxy-daemonset.yaml"}, Test: func(t *testing.T, suite *suite.ConformanceTestSuite) { t.Run("RunAndDelete", func(t *testing.T) { - t.Cleanup(func() { - if t.Failed() { - CollectAndDump(t, suite.RestConfig) - } - }) - ns := "gateway-conformance-infra" routeNN := types.NamespacedName{Name: "daemonset-route", Namespace: ns} gwNN := types.NamespacedName{Name: "eg-ds", Namespace: ns} diff --git a/test/e2e/tests/httproute_with_dynamic_resolver_backend.go b/test/e2e/tests/httproute_with_dynamic_resolver_backend.go index b609877331..9c688f3fd5 100644 --- a/test/e2e/tests/httproute_with_dynamic_resolver_backend.go +++ b/test/e2e/tests/httproute_with_dynamic_resolver_backend.go @@ -84,11 +84,6 @@ var DynamicResolverBackendTest = suite.ConformanceTest{ http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, expectedResponse) }) - t.Cleanup(func() { - if t.Failed() { - CollectAndDump(t, suite.RestConfig) - } - }) }, } @@ -142,10 +137,5 @@ var DynamicResolverBackendWithTLSTest = suite.ConformanceTest{ } http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, expectedResponse) }) - t.Cleanup(func() { - if t.Failed() { - CollectAndDump(t, suite.RestConfig) - } - }) }, } diff --git a/test/e2e/upgrade/eg_upgrade_test.go b/test/e2e/upgrade/eg_upgrade_test.go index 12bb99850d..7031f5ef7b 100644 --- a/test/e2e/upgrade/eg_upgrade_test.go +++ b/test/e2e/upgrade/eg_upgrade_test.go @@ -59,6 +59,7 @@ func TestEGUpgrade(t *testing.T) { BaseManifests: "upgrade/manifests.yaml", SupportedFeatures: sets.New(features.SupportGateway), SkipTests: skipTests, + Hook: e2e.Hook, }) if err != nil { t.Fatalf("Failed to create test suite: %v", err)