Skip to content

Commit 6c63e00

Browse files
[release-1.4] fix: use inferred supported features to set extendedSupportedFeatures (#4118)
* fix: use inferred supported features to set extendedSupportedFeatures Signed-off-by: Norwin Schnyder <[email protected]> * extend unit tests with assertion for extendedSupportedFeatures Signed-off-by: Norwin Schnyder <[email protected]> * refactor NewConformanceTestSuite Signed-off-by: Norwin Schnyder <[email protected]> --------- Signed-off-by: Norwin Schnyder <[email protected]> Co-authored-by: Norwin Schnyder <[email protected]>
1 parent 24ded58 commit 6c63e00

File tree

2 files changed

+55
-42
lines changed

2 files changed

+55
-42
lines changed

conformance/utils/suite/suite.go

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,22 @@ func NewConformanceTestSuite(options ConformanceOptions) (*ConformanceTestSuite,
227227
return nil, fmt.Errorf("no supported features were determined for test suite")
228228
}
229229

230+
extendedSupportedFeatures := make(map[ConformanceProfileName]FeaturesSet, 0)
231+
extendedUnsupportedFeatures := make(map[ConformanceProfileName]FeaturesSet, 0)
232+
233+
for _, conformanceProfileName := range options.ConformanceProfiles.UnsortedList() {
234+
conformanceProfile, err := getConformanceProfileForName(conformanceProfileName)
235+
if err != nil {
236+
return nil, fmt.Errorf("failed to retrieve conformance profile: %w", err)
237+
}
238+
// the use of a conformance profile implicitly enables any features of
239+
// that profile which are supported at a Core level of support.
240+
supportedFeatures = supportedFeatures.Union(conformanceProfile.CoreFeatures)
241+
242+
extendedSupportedFeatures[conformanceProfileName] = conformanceProfile.ExtendedFeatures.Intersection(supportedFeatures)
243+
extendedUnsupportedFeatures[conformanceProfileName] = conformanceProfile.ExtendedFeatures.Difference(supportedFeatures)
244+
}
245+
230246
config.SetupTimeoutConfig(&options.TimeoutConfig)
231247

232248
roundTripper := options.RoundTripper
@@ -284,8 +300,8 @@ func NewConformanceTestSuite(options ConformanceOptions) (*ConformanceTestSuite,
284300
UsableNetworkAddresses: options.UsableNetworkAddresses,
285301
UnusableNetworkAddresses: options.UnusableNetworkAddresses,
286302
results: make(map[string]testResult),
287-
extendedUnsupportedFeatures: make(map[ConformanceProfileName]sets.Set[features.FeatureName]),
288-
extendedSupportedFeatures: make(map[ConformanceProfileName]sets.Set[features.FeatureName]),
303+
extendedUnsupportedFeatures: extendedUnsupportedFeatures,
304+
extendedSupportedFeatures: extendedSupportedFeatures,
289305
conformanceProfiles: options.ConformanceProfiles,
290306
implementation: options.Implementation,
291307
mode: mode,
@@ -295,37 +311,6 @@ func NewConformanceTestSuite(options ConformanceOptions) (*ConformanceTestSuite,
295311
Hook: options.Hook,
296312
}
297313

298-
for _, conformanceProfileName := range options.ConformanceProfiles.UnsortedList() {
299-
conformanceProfile, err := getConformanceProfileForName(conformanceProfileName)
300-
if err != nil {
301-
return nil, fmt.Errorf("failed to retrieve conformance profile: %w", err)
302-
}
303-
// the use of a conformance profile implicitly enables any features of
304-
// that profile which are supported at a Core level of support.
305-
for _, f := range conformanceProfile.CoreFeatures.UnsortedList() {
306-
if !options.SupportedFeatures.Has(f) {
307-
suite.SupportedFeatures.Insert(f)
308-
}
309-
}
310-
for _, f := range conformanceProfile.ExtendedFeatures.UnsortedList() {
311-
if options.SupportedFeatures.Has(f) {
312-
if suite.extendedSupportedFeatures[conformanceProfileName] == nil {
313-
suite.extendedSupportedFeatures[conformanceProfileName] = FeaturesSet{}
314-
}
315-
suite.extendedSupportedFeatures[conformanceProfileName].Insert(f)
316-
} else {
317-
if suite.extendedUnsupportedFeatures[conformanceProfileName] == nil {
318-
suite.extendedUnsupportedFeatures[conformanceProfileName] = FeaturesSet{}
319-
}
320-
suite.extendedUnsupportedFeatures[conformanceProfileName].Insert(f)
321-
}
322-
// Add Exempt Features into unsupported features list
323-
if options.ExemptFeatures.Has(f) {
324-
suite.extendedUnsupportedFeatures[conformanceProfileName].Insert(f)
325-
}
326-
}
327-
}
328-
329314
// apply defaults
330315
if suite.BaseManifests == "" {
331316
suite.BaseManifests = "base/manifests.yaml"

conformance/utils/suite/suite_test.go

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -418,20 +418,21 @@ var statusFeatureNames = []string{
418418
"HTTPRouteHostRewrite",
419419
"HTTPRouteMethodMatching",
420420
"HTTPRoutePathRewrite",
421-
"TTPRouteQueryParamMatching",
421+
"HTTPRouteQueryParamMatching",
422422
"HTTPRouteResponseHeaderModification",
423423
"ReferenceGrant",
424424
}
425425

426426
func TestInferSupportedFeatures(t *testing.T) {
427427
testCases := []struct {
428-
name string
429-
allowAllFeatures bool
430-
supportedFeatures FeaturesSet
431-
exemptFeatures FeaturesSet
432-
ConformanceProfile sets.Set[ConformanceProfileName]
433-
expectedFeatures FeaturesSet
434-
expectedSource supportedFeaturesSource
428+
name string
429+
allowAllFeatures bool
430+
supportedFeatures FeaturesSet
431+
exemptFeatures FeaturesSet
432+
ConformanceProfile sets.Set[ConformanceProfileName]
433+
expectedFeatures FeaturesSet
434+
expectedExtendedFeatures map[ConformanceProfileName]sets.Set[features.FeatureName]
435+
expectedSource supportedFeaturesSource
435436
}{
436437
{
437438
name: "properly infer supported features",
@@ -458,10 +459,32 @@ func TestInferSupportedFeatures(t *testing.T) {
458459
expectedSource: supportedFeaturesSourceManual,
459460
},
460461
{
461-
name: "supports conformance profile - core",
462+
name: "supports conformance profile core with specified extended features",
463+
ConformanceProfile: sets.New(GatewayHTTPConformanceProfileName),
464+
supportedFeatures: sets.New[features.FeatureName]("GatewayPort8080"),
465+
expectedFeatures: sets.New[features.FeatureName]("Gateway", "HTTPRoute", "GatewayPort8080", "ReferenceGrant"),
466+
expectedSource: supportedFeaturesSourceManual,
467+
expectedExtendedFeatures: map[ConformanceProfileName]sets.Set[features.FeatureName]{
468+
GatewayHTTPConformanceProfileName: namesToFeatureSet([]string{
469+
"GatewayPort8080",
470+
}),
471+
},
472+
},
473+
{
474+
name: "supports conformance profile core with inferred extended features",
462475
ConformanceProfile: sets.New(GatewayHTTPConformanceProfileName),
463476
expectedFeatures: namesToFeatureSet(statusFeatureNames),
464477
expectedSource: supportedFeaturesSourceInferred,
478+
expectedExtendedFeatures: map[ConformanceProfileName]sets.Set[features.FeatureName]{
479+
GatewayHTTPConformanceProfileName: namesToFeatureSet([]string{
480+
"GatewayPort8080",
481+
"HTTPRouteHostRewrite",
482+
"HTTPRouteMethodMatching",
483+
"HTTPRoutePathRewrite",
484+
"HTTPRouteQueryParamMatching",
485+
"HTTPRouteResponseHeaderModification",
486+
}),
487+
},
465488
},
466489
}
467490

@@ -520,6 +543,11 @@ func TestInferSupportedFeatures(t *testing.T) {
520543
if equal := cSuite.SupportedFeatures.Equal(tc.expectedFeatures); !equal {
521544
t.Errorf("SupportedFeatures mismatch: got %v, want %v", cSuite.SupportedFeatures.UnsortedList(), tc.expectedFeatures.UnsortedList())
522545
}
546+
547+
if tc.expectedExtendedFeatures == nil {
548+
tc.expectedExtendedFeatures = make(map[ConformanceProfileName]sets.Set[features.FeatureName])
549+
}
550+
assert.Equal(t, tc.expectedExtendedFeatures, cSuite.extendedSupportedFeatures, "expectedExtendedFeatures mismatch")
523551
})
524552
}
525553
}

0 commit comments

Comments
 (0)