From 622be98418550cafd1fbec549f163a42509ad510 Mon Sep 17 00:00:00 2001 From: zirain Date: Tue, 7 May 2024 20:34:20 +0800 Subject: [PATCH] fix test Signed-off-by: zirain --- test/conformance/conformance_test.go | 35 ++------- .../experimental_conformance_test.go | 76 +++---------------- test/e2e/e2e_test.go | 5 +- .../e2e/merge_gateways/merge_gateways_test.go | 2 + test/e2e/tests/gateway_infra_resource.go | 4 +- test/e2e/upgrade/eg_upgrade_test.go | 2 + 6 files changed, 29 insertions(+), 95 deletions(-) diff --git a/test/conformance/conformance_test.go b/test/conformance/conformance_test.go index 945f98477e6..49e2645f1a8 100644 --- a/test/conformance/conformance_test.go +++ b/test/conformance/conformance_test.go @@ -12,42 +12,23 @@ import ( "flag" "testing" - "github.com/stretchr/testify/require" - "k8s.io/client-go/kubernetes" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/client/config" + "sigs.k8s.io/gateway-api/conformance" "sigs.k8s.io/gateway-api/conformance/tests" - "sigs.k8s.io/gateway-api/conformance/utils/flags" "sigs.k8s.io/gateway-api/conformance/utils/suite" "sigs.k8s.io/gateway-api/pkg/features" - - "github.com/envoyproxy/gateway/internal/envoygateway" ) func TestGatewayAPIConformance(t *testing.T) { flag.Parse() - clientCfg, err := config.GetConfig() - require.NoError(t, err) - - c, err := client.New(clientCfg, client.Options{Scheme: envoygateway.GetScheme()}) - require.NoError(t, err) - - cs, err := kubernetes.NewForConfig(clientCfg) - require.NoError(t, err) + opts := conformance.DefaultOptions(t) + opts.SkipTests = []string{ + tests.GatewayStaticAddresses.ShortName, + } + opts.SupportedFeatures = features.AllFeatures + opts.ExemptFeatures = features.MeshCoreFeatures - cSuite, err := suite.NewConformanceTestSuite(suite.ConformanceOptions{ - Client: c, - GatewayClassName: *flags.GatewayClassName, - Debug: *flags.ShowDebug, - Clientset: cs, - CleanupBaseResources: *flags.CleanupBaseResources, - SupportedFeatures: features.AllFeatures, - SkipTests: []string{ - tests.GatewayStaticAddresses.ShortName, - }, - ExemptFeatures: features.MeshCoreFeatures, - }) + cSuite, err := suite.NewConformanceTestSuite(opts) if err != nil { t.Fatalf("Error creating conformance test suite: %v", err) } diff --git a/test/conformance/experimental_conformance_test.go b/test/conformance/experimental_conformance_test.go index af1a19aa269..e64cee33b73 100644 --- a/test/conformance/experimental_conformance_test.go +++ b/test/conformance/experimental_conformance_test.go @@ -9,91 +9,39 @@ package conformance import ( + "flag" "os" "testing" "github.com/stretchr/testify/require" "k8s.io/apimachinery/pkg/util/sets" - "k8s.io/client-go/kubernetes" - "k8s.io/client-go/rest" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/client/config" + "sigs.k8s.io/gateway-api/conformance" conformancev1 "sigs.k8s.io/gateway-api/conformance/apis/v1" "sigs.k8s.io/gateway-api/conformance/tests" "sigs.k8s.io/gateway-api/conformance/utils/flags" "sigs.k8s.io/gateway-api/conformance/utils/suite" "sigs.k8s.io/gateway-api/pkg/features" "sigs.k8s.io/yaml" - - "github.com/envoyproxy/gateway/internal/envoygateway" -) - -var ( - cfg *rest.Config - k8sClientset *kubernetes.Clientset - mgrClient client.Client - implementation conformancev1.Implementation - conformanceProfiles sets.Set[suite.ConformanceProfileName] ) func TestExperimentalConformance(t *testing.T) { - var err error - cfg, err = config.GetConfig() - if err != nil { - t.Fatalf("Error loading Kubernetes config: %v", err) - } - mgrClient, err = client.New(cfg, client.Options{Scheme: envoygateway.GetScheme()}) - if err != nil { - t.Fatalf("Error initializing Kubernetes client: %v", err) - } - k8sClientset, err = kubernetes.NewForConfig(cfg) - if err != nil { - t.Fatalf("Error initializing Kubernetes REST client: %v", err) - } + flag.Parse() - // experimental conformance flags - conformanceProfiles = sets.New( + opts := conformance.DefaultOptions(t) + opts.SkipTests = []string{ + tests.GatewayStaticAddresses.ShortName, + } + opts.SupportedFeatures = features.AllFeatures + opts.ExemptFeatures = features.MeshCoreFeatures + opts.ConformanceProfiles = sets.New( suite.GatewayHTTPConformanceProfileName, suite.GatewayTLSConformanceProfileName, ) - // if some conformance profiles have been set, run the experimental conformance suite... - implementation = suite.ParseImplementation( - *flags.ImplementationOrganization, - *flags.ImplementationProject, - *flags.ImplementationURL, - *flags.ImplementationVersion, - *flags.ImplementationContact, - ) - if err != nil { - t.Fatalf("Error parsing implementation's details: %v", err) - } - - experimentalConformance(t) -} - -func experimentalConformance(t *testing.T) { 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, conformanceProfiles) + *flags.GatewayClassName, *flags.CleanupBaseResources, *flags.ShowDebug, *flags.EnableAllSupportedFeatures, opts.ConformanceProfiles) - cSuite, err := suite.NewConformanceTestSuite( - suite.ConformanceOptions{ - Client: mgrClient, - RestConfig: cfg, - // This Clientset is needed in addition to the client only because - // controller-runtime client doesn't support non-CRUD sub-resources yet (https://github.com/kubernetes-sigs/controller-runtime/issues/452). - Clientset: k8sClientset, - GatewayClassName: *flags.GatewayClassName, - Debug: *flags.ShowDebug, - CleanupBaseResources: *flags.CleanupBaseResources, - SupportedFeatures: features.AllFeatures, - SkipTests: []string{ - tests.GatewayStaticAddresses.ShortName, - }, - ExemptFeatures: features.MeshCoreFeatures, - Implementation: implementation, - ConformanceProfiles: conformanceProfiles, - }) + cSuite, err := suite.NewConformanceTestSuite(opts) if err != nil { t.Fatalf("error creating experimental conformance test suite: %v", err) } diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 6c5517a2517..5f088c5fcd1 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -18,6 +18,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client/config" gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2" + gwapiv1a3 "sigs.k8s.io/gateway-api/apis/v1alpha3" "sigs.k8s.io/gateway-api/conformance/utils/flags" "sigs.k8s.io/gateway-api/conformance/utils/suite" @@ -33,6 +34,7 @@ func TestE2E(t *testing.T) { c, err := client.New(cfg, client.Options{}) require.NoError(t, err) + require.NoError(t, gwapiv1a3.AddToScheme(c.Scheme())) require.NoError(t, gwapiv1a2.AddToScheme(c.Scheme())) require.NoError(t, gwapiv1.AddToScheme(c.Scheme())) require.NoError(t, egv1a1.AddToScheme(c.Scheme())) @@ -53,7 +55,8 @@ func TestE2E(t *testing.T) { ManifestFS: []fs.FS{Manifests}, RunTest: *flags.RunTest, SkipTests: []string{ - tests.ClientTimeoutTest.ShortName, // https://github.com/envoyproxy/gateway/issues/2720 + tests.ClientTimeoutTest.ShortName, // https://github.com/envoyproxy/gateway/issues/2720 + tests.GatewayInfraResourceTest.ShortName, // https://github.com/envoyproxy/gateway/issues/3191 }, }) if err != nil { diff --git a/test/e2e/merge_gateways/merge_gateways_test.go b/test/e2e/merge_gateways/merge_gateways_test.go index d9f76a31489..a1d02de9231 100644 --- a/test/e2e/merge_gateways/merge_gateways_test.go +++ b/test/e2e/merge_gateways/merge_gateways_test.go @@ -18,6 +18,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client/config" gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2" + gwapiv1a3 "sigs.k8s.io/gateway-api/apis/v1alpha3" "sigs.k8s.io/gateway-api/conformance/utils/flags" "sigs.k8s.io/gateway-api/conformance/utils/kubernetes" "sigs.k8s.io/gateway-api/conformance/utils/suite" @@ -35,6 +36,7 @@ func TestMergeGateways(t *testing.T) { c, err := client.New(cfg, client.Options{}) require.NoError(t, err) + require.NoError(t, gwapiv1a3.AddToScheme(c.Scheme())) require.NoError(t, gwapiv1a2.AddToScheme(c.Scheme())) require.NoError(t, gwapiv1.AddToScheme(c.Scheme())) require.NoError(t, egv1a1.AddToScheme(c.Scheme())) diff --git a/test/e2e/tests/gateway_infra_resource.go b/test/e2e/tests/gateway_infra_resource.go index c14cb145050..7a468b80f60 100644 --- a/test/e2e/tests/gateway_infra_resource.go +++ b/test/e2e/tests/gateway_infra_resource.go @@ -24,11 +24,9 @@ import ( ) func init() { - // nolint - // ConformanceTests = append(ConformanceTests, GatewayInfraResourceTest) + ConformanceTests = append(ConformanceTests, GatewayInfraResourceTest) } -// nolint var GatewayInfraResourceTest = suite.ConformanceTest{ ShortName: "GatewayInfraResourceTest", Description: "Gateway Infra Resource E2E Test", diff --git a/test/e2e/upgrade/eg_upgrade_test.go b/test/e2e/upgrade/eg_upgrade_test.go index 70573a7f966..145d6f523c9 100644 --- a/test/e2e/upgrade/eg_upgrade_test.go +++ b/test/e2e/upgrade/eg_upgrade_test.go @@ -18,6 +18,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client/config" gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2" + gwapiv1a3 "sigs.k8s.io/gateway-api/apis/v1alpha3" "sigs.k8s.io/gateway-api/conformance/utils/flags" "sigs.k8s.io/gateway-api/conformance/utils/suite" @@ -34,6 +35,7 @@ func TestEGUpgrade(t *testing.T) { c, err := client.New(cfg, client.Options{}) require.NoError(t, err) + require.NoError(t, gwapiv1a3.AddToScheme(c.Scheme())) require.NoError(t, gwapiv1a2.AddToScheme(c.Scheme())) require.NoError(t, gwapiv1.AddToScheme(c.Scheme())) require.NoError(t, egv1a1.AddToScheme(c.Scheme()))