Skip to content

Commit c26512f

Browse files
authored
fix: use inferred supported features to set extendedSupportedFeatures (#4113)
* 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]>
1 parent 4c403cf commit c26512f

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
@@ -233,6 +233,22 @@ func NewConformanceTestSuite(options ConformanceOptions) (*ConformanceTestSuite,
233233
return nil, fmt.Errorf("no supported features were determined for test suite")
234234
}
235235

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

238254
roundTripper := options.RoundTripper
@@ -290,8 +306,8 @@ func NewConformanceTestSuite(options ConformanceOptions) (*ConformanceTestSuite,
290306
UsableNetworkAddresses: options.UsableNetworkAddresses,
291307
UnusableNetworkAddresses: options.UnusableNetworkAddresses,
292308
results: make(map[string]testResult),
293-
extendedUnsupportedFeatures: make(map[ConformanceProfileName]sets.Set[features.FeatureName]),
294-
extendedSupportedFeatures: make(map[ConformanceProfileName]sets.Set[features.FeatureName]),
309+
extendedUnsupportedFeatures: extendedUnsupportedFeatures,
310+
extendedSupportedFeatures: extendedSupportedFeatures,
295311
conformanceProfiles: options.ConformanceProfiles,
296312
implementation: options.Implementation,
297313
mode: mode,
@@ -301,37 +317,6 @@ func NewConformanceTestSuite(options ConformanceOptions) (*ConformanceTestSuite,
301317
Hook: options.Hook,
302318
}
303319

304-
for _, conformanceProfileName := range options.ConformanceProfiles.UnsortedList() {
305-
conformanceProfile, err := getConformanceProfileForName(conformanceProfileName)
306-
if err != nil {
307-
return nil, fmt.Errorf("failed to retrieve conformance profile: %w", err)
308-
}
309-
// the use of a conformance profile implicitly enables any features of
310-
// that profile which are supported at a Core level of support.
311-
for _, f := range conformanceProfile.CoreFeatures.UnsortedList() {
312-
if !options.SupportedFeatures.Has(f) {
313-
suite.SupportedFeatures.Insert(f)
314-
}
315-
}
316-
for _, f := range conformanceProfile.ExtendedFeatures.UnsortedList() {
317-
if options.SupportedFeatures.Has(f) {
318-
if suite.extendedSupportedFeatures[conformanceProfileName] == nil {
319-
suite.extendedSupportedFeatures[conformanceProfileName] = FeaturesSet{}
320-
}
321-
suite.extendedSupportedFeatures[conformanceProfileName].Insert(f)
322-
} else {
323-
if suite.extendedUnsupportedFeatures[conformanceProfileName] == nil {
324-
suite.extendedUnsupportedFeatures[conformanceProfileName] = FeaturesSet{}
325-
}
326-
suite.extendedUnsupportedFeatures[conformanceProfileName].Insert(f)
327-
}
328-
// Add Exempt Features into unsupported features list
329-
if options.ExemptFeatures.Has(f) {
330-
suite.extendedUnsupportedFeatures[conformanceProfileName].Insert(f)
331-
}
332-
}
333-
}
334-
335320
// apply defaults
336321
if suite.BaseManifests == "" {
337322
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
@@ -419,20 +419,21 @@ var gwcStatusFeatureNames = []string{
419419
"HTTPRouteHostRewrite",
420420
"HTTPRouteMethodMatching",
421421
"HTTPRoutePathRewrite",
422-
"TTPRouteQueryParamMatching",
422+
"HTTPRouteQueryParamMatching",
423423
"HTTPRouteResponseHeaderModification",
424424
"ReferenceGrant",
425425
}
426426

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

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

0 commit comments

Comments
 (0)