Skip to content

Commit

Permalink
fix conformance test
Browse files Browse the repository at this point in the history
Signed-off-by: zirain <[email protected]>
  • Loading branch information
zirain committed May 7, 2024
1 parent e9f8964 commit 6c70251
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 46 deletions.
36 changes: 22 additions & 14 deletions test/conformance/conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,50 @@ import (
"k8s.io/client-go/kubernetes"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"
v1 "sigs.k8s.io/gateway-api/apis/v1"
"sigs.k8s.io/gateway-api/apis/v1"
"sigs.k8s.io/gateway-api/apis/v1alpha2"
"sigs.k8s.io/gateway-api/apis/v1alpha3"
"sigs.k8s.io/gateway-api/apis/v1beta1"
"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"
)

func TestGatewayAPIConformance(t *testing.T) {
flag.Parse()

cfg, err := config.GetConfig()
clientCfg, err := config.GetConfig()
require.NoError(t, err)

client, err := client.New(cfg, client.Options{})
c, err := client.New(clientCfg, client.Options{})
require.NoError(t, err)

clientset, err := kubernetes.NewForConfig(cfg)
cs, err := kubernetes.NewForConfig(clientCfg)
require.NoError(t, err)

require.NoError(t, v1alpha2.AddToScheme(client.Scheme()))
require.NoError(t, v1beta1.AddToScheme(client.Scheme()))
require.NoError(t, v1.AddToScheme(client.Scheme()))
require.NoError(t, v1alpha3.AddToScheme(c.Scheme()))
require.NoError(t, v1alpha2.AddToScheme(c.Scheme()))
require.NoError(t, v1beta1.AddToScheme(c.Scheme()))
require.NoError(t, v1.AddToScheme(c.Scheme()))

cSuite := suite.New(suite.Options{
Client: client,
cSuite, err := suite.NewConformanceTestSuite(suite.ConformanceOptions{
Client: c,
GatewayClassName: *flags.GatewayClassName,
Debug: *flags.ShowDebug,
Clientset: clientset,
Clientset: cs,
CleanupBaseResources: *flags.CleanupBaseResources,
SupportedFeatures: suite.AllFeatures,
SupportedFeatures: features.AllFeatures,
SkipTests: []string{
tests.GatewayStaticAddresses.ShortName,
},
ExemptFeatures: suite.MeshCoreFeatures,
ExemptFeatures: features.MeshCoreFeatures,
})
cSuite.Setup(t)
cSuite.Run(t, tests.ConformanceTests)
if err != nil {
t.Fatalf("Error creating conformance test suite: %v", err)
}
cSuite.Setup(t, tests.ConformanceTests)
if err := cSuite.Run(t, tests.ConformanceTests); err != nil {
t.Fatalf("Error running conformance tests: %v", err)
}
}
61 changes: 29 additions & 32 deletions test/conformance/experimental_conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,23 @@ import (
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/yaml"

v1 "sigs.k8s.io/gateway-api/apis/v1"
"sigs.k8s.io/gateway-api/apis/v1"
"sigs.k8s.io/gateway-api/apis/v1alpha2"
"sigs.k8s.io/gateway-api/apis/v1alpha3"
"sigs.k8s.io/gateway-api/apis/v1beta1"
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"
)

var (
cfg *rest.Config
k8sClientset *kubernetes.Clientset
mgrClient client.Client
implementation *conformancev1.Implementation
implementation conformancev1.Implementation
conformanceProfiles sets.Set[suite.ConformanceProfileName]
)

Expand All @@ -52,21 +53,19 @@ func TestExperimentalConformance(t *testing.T) {
t.Fatalf("Error initializing Kubernetes REST client: %v", err)
}

err = v1alpha2.AddToScheme(mgrClient.Scheme())
require.NoError(t, err)
err = v1beta1.AddToScheme(mgrClient.Scheme())
require.NoError(t, err)
err = v1.AddToScheme(mgrClient.Scheme())
require.NoError(t, err)
require.NoError(t, v1alpha3.AddToScheme(mgrClient.Scheme()))
require.NoError(t, v1alpha2.AddToScheme(mgrClient.Scheme()))
require.NoError(t, v1beta1.AddToScheme(mgrClient.Scheme()))
require.NoError(t, v1.AddToScheme(mgrClient.Scheme()))

// experimental conformance flags
conformanceProfiles = sets.New(
suite.HTTPConformanceProfileName,
suite.TLSConformanceProfileName,
suite.GatewayHTTPConformanceProfileName,
suite.GatewayTLSConformanceProfileName,
)

// if some conformance profiles have been set, run the experimental conformance suite...
implementation, err = suite.ParseImplementation(
implementation = suite.ParseImplementation(
*flags.ImplementationOrganization,
*flags.ImplementationProject,
*flags.ImplementationURL,
Expand All @@ -84,31 +83,29 @@ 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)

cSuite, err := suite.NewExperimentalConformanceTestSuite(
suite.ExperimentalConformanceOptions{
Options: suite.Options{
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: suite.AllFeatures,
SkipTests: []string{
tests.GatewayStaticAddresses.ShortName,
},
ExemptFeatures: suite.MeshCoreFeatures,
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,
},
Implementation: *implementation,
ExemptFeatures: features.MeshCoreFeatures,
Implementation: implementation,
ConformanceProfiles: conformanceProfiles,
})
if err != nil {
t.Fatalf("error creating experimental conformance test suite: %v", err)
}

cSuite.Setup(t)
cSuite.Setup(t, tests.ConformanceTests)
err = cSuite.Run(t, tests.ConformanceTests)
if err != nil {
t.Fatalf("error running conformance profile report: %v", err)
Expand All @@ -122,7 +119,7 @@ func experimentalConformance(t *testing.T) {
require.NoError(t, err)
}

func experimentalConformanceReport(logf func(string, ...any), report confv1a1.ConformanceReport, output string) error {
func experimentalConformanceReport(logf func(string, ...any), report conformancev1.ConformanceReport, output string) error {
rawReport, err := yaml.Marshal(report)
if err != nil {
return err
Expand Down

0 comments on commit 6c70251

Please sign in to comment.