From b85174a868892238ff589643da738f492fda4e35 Mon Sep 17 00:00:00 2001 From: Huang Xin Date: Sat, 28 Jan 2023 14:23:09 +0800 Subject: [PATCH] Move to K8s sets util. Signed-off-by: Huang Xin --- conformance/conformance_test.go | 9 ++++--- conformance/utils/suite/suite.go | 42 ++++++++++++++++---------------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/conformance/conformance_test.go b/conformance/conformance_test.go index 14c3d33a5a..55d5929399 100644 --- a/conformance/conformance_test.go +++ b/conformance/conformance_test.go @@ -27,6 +27,7 @@ import ( "sigs.k8s.io/gateway-api/conformance/utils/flags" "sigs.k8s.io/gateway-api/conformance/utils/suite" + "k8s.io/apimachinery/pkg/util/sets" _ "k8s.io/client-go/plugin/pkg/client/auth" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/config" @@ -47,7 +48,7 @@ func TestConformance(t *testing.T) { supportedFeatures := parseSupportedFeatures(*flags.SupportedFeatures) exemptFeatures := parseSupportedFeatures(*flags.ExemptFeatures) for feature := range exemptFeatures { - supportedFeatures[feature] = false + supportedFeatures.Delete(feature) } t.Logf("Running conformance tests with %s GatewayClass\n cleanup: %t\n debug: %t\n supported features: [%v]\n exempt features: [%v]", @@ -67,10 +68,10 @@ func TestConformance(t *testing.T) { // parseSupportedFeatures parses flag arguments and converts the string to // map[suite.SupportedFeature]bool -func parseSupportedFeatures(f string) map[suite.SupportedFeature]bool { - res := map[suite.SupportedFeature]bool{} +func parseSupportedFeatures(f string) sets.Set[suite.SupportedFeature] { + res := sets.Set[suite.SupportedFeature]{} for _, value := range strings.Split(f, ",") { - res[suite.SupportedFeature(value)] = true + res.Insert(suite.SupportedFeature(value)) } return res } diff --git a/conformance/utils/suite/suite.go b/conformance/utils/suite/suite.go index 11a79f88ce..1d89924405 100644 --- a/conformance/utils/suite/suite.go +++ b/conformance/utils/suite/suite.go @@ -74,8 +74,8 @@ const ( // StandardCoreFeatures are the features that are required to be conformant with // the Core API features that are part of the Standard release channel. -var StandardCoreFeatures = map[SupportedFeature]bool{ - SupportReferenceGrant: true, +var StandardCoreFeatures = sets.Set[SupportedFeature]{ + SupportReferenceGrant: {}, } // AllFeatures contains all the supported features and can be used to run all @@ -83,19 +83,19 @@ var StandardCoreFeatures = map[SupportedFeature]bool{ // // Note that the AllFeatures must in sync with defined features when the // feature constants change. -var AllFeatures = map[SupportedFeature]bool{ - SupportReferenceGrant: true, - SupportTLSRoute: true, - SupportHTTPRouteQueryParamMatching: true, - SupportHTTPRouteMethodMatching: true, - SupportHTTPResponseHeaderModification: true, - SupportRouteDestinationPortMatching: true, - SupportGatewayClassObservedGenerationBump: true, - SupportHTTPRoutePortRedirect: true, - SupportHTTPRouteSchemeRedirect: true, - SupportHTTPRoutePathRedirect: true, - SupportHTTPRouteHostRewrite: true, - SupportHTTPRoutePathRewrite: true, +var AllFeatures = sets.Set[SupportedFeature]{ + SupportReferenceGrant: {}, + SupportTLSRoute: {}, + SupportHTTPRouteQueryParamMatching: {}, + SupportHTTPRouteMethodMatching: {}, + SupportHTTPResponseHeaderModification: {}, + SupportRouteDestinationPortMatching: {}, + SupportGatewayClassObservedGenerationBump: {}, + SupportHTTPRoutePortRedirect: {}, + SupportHTTPRouteSchemeRedirect: {}, + SupportHTTPRoutePathRedirect: {}, + SupportHTTPRouteHostRewrite: {}, + SupportHTTPRoutePathRewrite: {}, } // ConformanceTestSuite defines the test suite used to run Gateway API @@ -109,7 +109,7 @@ type ConformanceTestSuite struct { Cleanup bool BaseManifests string Applier kubernetes.Applier - SupportedFeatures map[SupportedFeature]bool + SupportedFeatures sets.Set[SupportedFeature] TimeoutConfig config.TimeoutConfig SkipTests sets.Set[string] } @@ -133,7 +133,7 @@ type Options struct { // CleanupBaseResources indicates whether or not the base test // resources such as Gateways should be cleaned up after the run. CleanupBaseResources bool - SupportedFeatures map[SupportedFeature]bool + SupportedFeatures sets.Set[SupportedFeature] EnableAllSupportedFeatures bool TimeoutConfig config.TimeoutConfig // SkipTests contains all the tests not to be run and can be used to opt out @@ -155,9 +155,9 @@ func New(s Options) *ConformanceTestSuite { } else if s.SupportedFeatures == nil { s.SupportedFeatures = StandardCoreFeatures } else { - for feature, val := range StandardCoreFeatures { - if _, ok := s.SupportedFeatures[feature]; !ok { - s.SupportedFeatures[feature] = val + for feature := range StandardCoreFeatures { + if !s.SupportedFeatures.Has(feature) { + s.SupportedFeatures.Insert(feature) } } } @@ -245,7 +245,7 @@ func (test *ConformanceTest) Run(t *testing.T, suite *ConformanceTestSuite) { // Check that all features exercised by the test have been opted into by // the suite. for _, feature := range test.Features { - if supported, ok := suite.SupportedFeatures[feature]; !ok || !supported { + if suite.SupportedFeatures.Has(feature) { t.Skipf("Skipping %s: suite does not support %s", test.ShortName, feature) } }