@@ -6,6 +6,7 @@ package feature
66
77import (
88 "context"
9+ "strings"
910 "testing"
1011
1112 "gotest.tools/v3/assert"
@@ -14,6 +15,7 @@ import (
1415func TestDefaults (t * testing.T ) {
1516 t .Parallel ()
1617 gate := NewGate ()
18+ ctx := NewContext (context .Background (), gate )
1719
1820 assert .Assert (t , false == gate .Enabled (AppendCustomQueries ))
1921 assert .Assert (t , true == gate .Enabled (AutoCreateUserSchema ))
@@ -24,16 +26,17 @@ func TestDefaults(t *testing.T) {
2426 assert .Assert (t , false == gate .Enabled (TablespaceVolumes ))
2527 assert .Assert (t , false == gate .Enabled (VolumeSnapshots ))
2628
27- assert .Equal (t , gate . String ( ), "" )
29+ assert .Equal (t , ShowAssigned ( ctx ), "" )
2830}
2931
3032func TestStringFormat (t * testing.T ) {
3133 t .Parallel ()
3234 gate := NewGate ()
35+ ctx := NewContext (context .Background (), gate )
3336
3437 assert .NilError (t , gate .Set ("" ))
3538 assert .NilError (t , gate .Set ("TablespaceVolumes=true" ))
36- assert .Equal (t , gate . String ( ), "TablespaceVolumes=true" )
39+ assert .Equal (t , ShowAssigned ( ctx ), "TablespaceVolumes=true" )
3740 assert .Assert (t , true == gate .Enabled (TablespaceVolumes ))
3841
3942 err := gate .Set ("NotAGate=true" )
@@ -54,20 +57,20 @@ func TestContext(t *testing.T) {
5457 gate := NewGate ()
5558 ctx := NewContext (context .Background (), gate )
5659
57- // ShowGates returns all fields that are turned on, whether explicitly
58- // by the user or implicitly due to feature default.
59- // Currently, the only feature defaulting to true is `AutoCreateUserSchema`.
60- assert .Equal (t , ShowGates (ctx ), "AutoCreateUserSchema=true" )
60+ assert .Equal (t , ShowAssigned (ctx ), "" )
61+ assert .Assert (t , ShowEnabled (ctx ) != "" ) // This assumes some feature is enabled by default.
6162
6263 assert .NilError (t , gate .Set ("TablespaceVolumes=true" ))
63- assert .Assert (t , true == Enabled (ctx , TablespaceVolumes ))
64- assert .Equal (t , ShowGates (ctx ), "AutoCreateUserSchema=true,TablespaceVolumes=true" )
64+ assert .Assert (t , Enabled (ctx , TablespaceVolumes ))
65+ assert .Equal (t , ShowAssigned (ctx ), "TablespaceVolumes=true" )
66+ assert .Assert (t ,
67+ strings .Contains (ShowEnabled (ctx ), "TablespaceVolumes=true" ),
68+ "got: %v" , ShowEnabled (ctx ))
6569
66- assert .NilError (t , gate .SetFromMap (map [string ]bool {
67- TablespaceVolumes : false ,
68- AutoCreateUserSchema : false ,
69- }))
70- assert .Assert (t , false == Enabled (ctx , TablespaceVolumes ))
71- assert .Assert (t , false == Enabled (ctx , AutoCreateUserSchema ))
72- assert .Equal (t , ShowGates (ctx ), "" )
70+ assert .NilError (t , gate .SetFromMap (map [string ]bool {TablespaceVolumes : false }))
71+ assert .Assert (t , ! Enabled (ctx , TablespaceVolumes ))
72+ assert .Equal (t , ShowAssigned (ctx ), "TablespaceVolumes=false" )
73+ assert .Assert (t ,
74+ ! strings .Contains (ShowEnabled (ctx ), "TablespaceVolumes" ),
75+ "got: %v" , ShowEnabled (ctx ))
7376}
0 commit comments