@@ -21,6 +21,7 @@ import (
21
21
22
22
"github.com/spf13/pflag"
23
23
"github.com/stretchr/testify/assert"
24
+ "go.uber.org/zap/zaptest"
24
25
)
25
26
26
27
func TestFeatureGateFlag (t * testing.T ) {
@@ -203,7 +204,7 @@ func TestFeatureGateFlag(t *testing.T) {
203
204
for i , test := range tests {
204
205
t .Run (test .arg , func (t * testing.T ) {
205
206
fs := pflag .NewFlagSet ("testfeaturegateflag" , pflag .ContinueOnError )
206
- f := NewFeatureGate ( )
207
+ f := New ( "test" , zaptest . NewLogger ( t ) )
207
208
f .Add (map [Feature ]FeatureSpec {
208
209
testAlphaGate : {Default : false , PreRelease : Alpha },
209
210
testBetaGate : {Default : false , PreRelease : Beta },
@@ -232,7 +233,7 @@ func TestFeatureGateOverride(t *testing.T) {
232
233
const testBetaGate Feature = "TestBeta"
233
234
234
235
// Don't parse the flag, assert defaults are used.
235
- var f * featureGate = NewFeatureGate ( )
236
+ var f = New ( "test" , zaptest . NewLogger ( t ) )
236
237
f .Add (map [Feature ]FeatureSpec {
237
238
testAlphaGate : {Default : false , PreRelease : Alpha },
238
239
testBetaGate : {Default : false , PreRelease : Beta },
@@ -261,7 +262,7 @@ func TestFeatureGateFlagDefaults(t *testing.T) {
261
262
const testBetaGate Feature = "TestBeta"
262
263
263
264
// Don't parse the flag, assert defaults are used.
264
- var f * featureGate = NewFeatureGate ( )
265
+ var f = New ( "test" , zaptest . NewLogger ( t ) )
265
266
f .Add (map [Feature ]FeatureSpec {
266
267
testAlphaGate : {Default : false , PreRelease : Alpha },
267
268
testBetaGate : {Default : true , PreRelease : Beta },
@@ -285,7 +286,7 @@ func TestFeatureGateKnownFeatures(t *testing.T) {
285
286
)
286
287
287
288
// Don't parse the flag, assert defaults are used.
288
- var f * featureGate = NewFeatureGate ( )
289
+ var f = New ( "test" , zaptest . NewLogger ( t ) )
289
290
f .Add (map [Feature ]FeatureSpec {
290
291
testAlphaGate : {Default : false , PreRelease : Alpha },
291
292
testBetaGate : {Default : true , PreRelease : Beta },
@@ -392,7 +393,7 @@ func TestFeatureGateSetFromMap(t *testing.T) {
392
393
}
393
394
for i , test := range tests {
394
395
t .Run (fmt .Sprintf ("SetFromMap %s" , test .name ), func (t * testing.T ) {
395
- f := NewFeatureGate ( )
396
+ f := New ( "test" , zaptest . NewLogger ( t ) )
396
397
f .Add (map [Feature ]FeatureSpec {
397
398
testAlphaGate : {Default : false , PreRelease : Alpha },
398
399
testBetaGate : {Default : false , PreRelease : Beta },
@@ -462,7 +463,7 @@ func TestFeatureGateString(t *testing.T) {
462
463
}
463
464
for i , test := range tests {
464
465
t .Run (fmt .Sprintf ("SetFromMap %s" , test .expect ), func (t * testing.T ) {
465
- f := NewFeatureGate ( )
466
+ f := New ( "test" , zaptest . NewLogger ( t ) )
466
467
f .Add (featuremap )
467
468
f .SetFromMap (test .setmap )
468
469
result := f .String ()
@@ -475,7 +476,7 @@ func TestFeatureGateString(t *testing.T) {
475
476
476
477
func TestFeatureGateOverrideDefault (t * testing.T ) {
477
478
t .Run ("overrides take effect" , func (t * testing.T ) {
478
- f := NewFeatureGate ( )
479
+ f := New ( "test" , zaptest . NewLogger ( t ) )
479
480
if err := f .Add (map [Feature ]FeatureSpec {
480
481
"TestFeature1" : {Default : true },
481
482
"TestFeature2" : {Default : false },
@@ -497,7 +498,7 @@ func TestFeatureGateOverrideDefault(t *testing.T) {
497
498
})
498
499
499
500
t .Run ("overrides are preserved across deep copies" , func (t * testing.T ) {
500
- f := NewFeatureGate ( )
501
+ f := New ( "test" , zaptest . NewLogger ( t ) )
501
502
if err := f .Add (map [Feature ]FeatureSpec {"TestFeature" : {Default : false }}); err != nil {
502
503
t .Fatal (err )
503
504
}
@@ -511,7 +512,7 @@ func TestFeatureGateOverrideDefault(t *testing.T) {
511
512
})
512
513
513
514
t .Run ("reflected in known features" , func (t * testing.T ) {
514
- f := NewFeatureGate ( )
515
+ f := New ( "test" , zaptest . NewLogger ( t ) )
515
516
if err := f .Add (map [Feature ]FeatureSpec {"TestFeature" : {
516
517
Default : false ,
517
518
PreRelease : Alpha ,
@@ -537,7 +538,7 @@ func TestFeatureGateOverrideDefault(t *testing.T) {
537
538
})
538
539
539
540
t .Run ("may not change default for specs with locked defaults" , func (t * testing.T ) {
540
- f := NewFeatureGate ( )
541
+ f := New ( "test" , zaptest . NewLogger ( t ) )
541
542
if err := f .Add (map [Feature ]FeatureSpec {
542
543
"LockedFeature" : {
543
544
Default : true ,
@@ -555,7 +556,7 @@ func TestFeatureGateOverrideDefault(t *testing.T) {
555
556
})
556
557
557
558
t .Run ("does not supersede explicitly-set value" , func (t * testing.T ) {
558
- f := NewFeatureGate ( )
559
+ f := New ( "test" , zaptest . NewLogger ( t ) )
559
560
if err := f .Add (map [Feature ]FeatureSpec {"TestFeature" : {Default : true }}); err != nil {
560
561
t .Fatal (err )
561
562
}
@@ -571,7 +572,7 @@ func TestFeatureGateOverrideDefault(t *testing.T) {
571
572
})
572
573
573
574
t .Run ("prevents re-registration of feature spec after overriding default" , func (t * testing.T ) {
574
- f := NewFeatureGate ( )
575
+ f := New ( "test" , zaptest . NewLogger ( t ) )
575
576
if err := f .Add (map [Feature ]FeatureSpec {
576
577
"TestFeature" : {
577
578
Default : true ,
@@ -594,14 +595,14 @@ func TestFeatureGateOverrideDefault(t *testing.T) {
594
595
})
595
596
596
597
t .Run ("does not allow override for an unknown feature" , func (t * testing.T ) {
597
- f := NewFeatureGate ( )
598
+ f := New ( "test" , zaptest . NewLogger ( t ) )
598
599
if err := f .OverrideDefault ("TestFeature" , true ); err == nil {
599
600
t .Error ("expected an error to be returned in attempt to override default for unregistered feature" )
600
601
}
601
602
})
602
603
603
604
t .Run ("returns error if already added to flag set" , func (t * testing.T ) {
604
- f := NewFeatureGate ( )
605
+ f := New ( "test" , zaptest . NewLogger ( t ) )
605
606
fs := pflag .NewFlagSet ("test" , pflag .ContinueOnError )
606
607
f .AddFlag (fs )
607
608
0 commit comments