Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
Signed-off-by: zirain <zirain2009@gmail.com>
  • Loading branch information
zirain committed May 7, 2024
1 parent 2868700 commit 622be98
Showing 6 changed files with 29 additions and 95 deletions.
35 changes: 8 additions & 27 deletions test/conformance/conformance_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
76 changes: 12 additions & 64 deletions test/conformance/experimental_conformance_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
5 changes: 4 additions & 1 deletion test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
@@ -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 {
2 changes: 2 additions & 0 deletions test/e2e/merge_gateways/merge_gateways_test.go
Original file line number Diff line number Diff line change
@@ -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()))
4 changes: 1 addition & 3 deletions test/e2e/tests/gateway_infra_resource.go
Original file line number Diff line number Diff line change
@@ -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",
2 changes: 2 additions & 0 deletions test/e2e/upgrade/eg_upgrade_test.go
Original file line number Diff line number Diff line change
@@ -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()))

0 comments on commit 622be98

Please sign in to comment.