Skip to content

Commit 881642e

Browse files
committed
test: extend unit test to cover the DisableAutoPrefix feature gate
Signed-off-by: Feruzjon Muyassarov <[email protected]>
1 parent 9470726 commit 881642e

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

pkg/nfd-master/nfd-master-internal_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,33 @@ func newFakeMaster(opts ...NfdMasterOption) *nfdMaster {
134134
return m.(*nfdMaster)
135135
}
136136

137+
func newFakeMasterWithFeatureGate(opts ...NfdMasterOption) *nfdMaster {
138+
nfdCli := fakenfdclient.NewSimpleClientset()
139+
defaultOpts := []NfdMasterOption{
140+
withNodeName(testNodeName),
141+
withConfig(&NFDConfig{Restrictions: Restrictions{AllowOverwrite: true}}),
142+
WithKubernetesClient(fakeclient.NewSimpleClientset()),
143+
withNFDClient(nfdCli),
144+
}
145+
m, err := NewNfdMaster(append(defaultOpts, opts...)...)
146+
if err != nil {
147+
panic(err)
148+
}
149+
// Add FeatureGates
150+
if err := features.NFDMutableFeatureGate.Add(features.DefaultNFDFeatureGates); err != nil {
151+
panic(err)
152+
}
153+
if err := features.NFDMutableFeatureGate.Set("DisableAutoPrefix=true"); err != nil {
154+
panic(err)
155+
}
156+
// Enable DisableAutoPrefix feature gate
157+
if !features.NFDFeatureGate.Enabled(features.DisableAutoPrefix) {
158+
err = errors.New("DisableAutoPrefix feature gate is not enabled")
159+
panic(err)
160+
}
161+
return m.(*nfdMaster)
162+
}
163+
137164
func TestUpdateNodeObject(t *testing.T) {
138165
Convey("When I update the node using fake client", t, func() {
139166
featureLabels := map[string]string{
@@ -432,6 +459,28 @@ func TestFilterLabels(t *testing.T) {
432459
}
433460
})
434461
}
462+
// Create a new fake master with the feature gate enabled
463+
fakeMaster = newFakeMasterWithFeatureGate()
464+
tcs = []TC{
465+
{
466+
description: "Unprefixed should be allowed",
467+
labelName: "test-label",
468+
labelValue: "test-value",
469+
expectedValue: "test-value",
470+
},
471+
}
472+
for _, tc := range tcs {
473+
t.Run(tc.description, func(t *testing.T) {
474+
labelValue, err := fakeMaster.filterFeatureLabel(tc.labelName, tc.labelValue, &tc.features)
475+
476+
Convey("Label should not be filtered out", t, func() {
477+
So(err, ShouldBeNil)
478+
})
479+
Convey("Label value should be correct", t, func() {
480+
So(labelValue, ShouldEqual, tc.expectedValue)
481+
})
482+
})
483+
}
435484
}
436485

437486
func TestCreatePatches(t *testing.T) {

0 commit comments

Comments
 (0)