github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/engine/features_test.go (about) 1 package engine 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/keybase/client/go/libkb" 8 "github.com/keybase/clockwork" 9 "github.com/stretchr/testify/require" 10 ) 11 12 func TestFeatureFlagSet(t *testing.T) { 13 tc := SetupEngineTest(t, "features") 14 defer tc.Cleanup() 15 fakeClock := clockwork.NewFakeClockAt(time.Now()) 16 tc.G.SetClock(fakeClock) 17 m := NewMetaContextForTest(tc) 18 CreateAndSignupFakeUserPaper(tc, "feat") 19 20 testFeature := libkb.Feature("test_feature") 21 22 // enable the feature server side through test endpoint 23 _, err := tc.G.API.Post(m, libkb.APIArg{ 24 Endpoint: "test/feature", 25 SessionType: libkb.APISessionTypeREQUIRED, 26 Args: libkb.HTTPArgs{ 27 "feature": libkb.S{Val: string(testFeature)}, 28 "value": libkb.I{Val: 1}, 29 "cache_sec": libkb.I{Val: 100}, 30 }, 31 }) 32 require.NoError(t, err) 33 34 // check it is on 35 on, err := tc.G.FeatureFlags.EnabledWithError(m, testFeature) 36 require.NoError(t, err) 37 require.True(t, on) 38 39 // turn it off server side 40 _, err = tc.G.API.Post(m, libkb.APIArg{ 41 Endpoint: "test/feature", 42 SessionType: libkb.APISessionTypeREQUIRED, 43 Args: libkb.HTTPArgs{ 44 "feature": libkb.S{Val: string(testFeature)}, 45 "value": libkb.I{Val: 0}, 46 "cache_sec": libkb.I{Val: 100}, 47 }, 48 }) 49 require.NoError(t, err) 50 51 // Still on, since it's still cached. 52 on, err = tc.G.FeatureFlags.EnabledWithError(m, testFeature) 53 require.NoError(t, err) 54 require.True(t, on) 55 56 fakeClock.Advance(time.Hour * 10) 57 for i := 0; i < 2; i++ { 58 on, err = tc.G.FeatureFlags.EnabledWithError(m, testFeature) 59 require.NoError(t, err) 60 require.False(t, on) 61 } 62 }