Skip to content

Commit

Permalink
Move to K8s sets util.
Browse files Browse the repository at this point in the history
Signed-off-by: Huang Xin <[email protected]>
  • Loading branch information
gyohuangxin committed Jan 28, 2023
1 parent 4d558b8 commit b85174a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
9 changes: 5 additions & 4 deletions conformance/conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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]",
Expand All @@ -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
}
42 changes: 21 additions & 21 deletions conformance/utils/suite/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,28 @@ 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
// conformance tests with `all-features` flag.
//
// 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
Expand All @@ -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]
}
Expand All @@ -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
Expand All @@ -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)
}
}
}
Expand Down Expand Up @@ -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)
}
}
Expand Down

0 comments on commit b85174a

Please sign in to comment.