@@ -134,6 +134,33 @@ func newFakeMaster(opts ...NfdMasterOption) *nfdMaster {
134
134
return m .(* nfdMaster )
135
135
}
136
136
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
+
137
164
func TestUpdateNodeObject (t * testing.T ) {
138
165
Convey ("When I update the node using fake client" , t , func () {
139
166
featureLabels := map [string ]string {
@@ -432,6 +459,28 @@ func TestFilterLabels(t *testing.T) {
432
459
}
433
460
})
434
461
}
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
+ }
435
484
}
436
485
437
486
func TestCreatePatches (t * testing.T ) {
0 commit comments