Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
adding more docs
  • Loading branch information
grambbledook committed Nov 4, 2025
commit 44631092e07babfa3f828b286934aee957cb55f4
6 changes: 6 additions & 0 deletions pkg/infra/featureflags/testing/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func (c *TestClient) IsEnabled(ctx context.Context, flag string) bool {
return c.delegate.Boolean(ctx, flag, false, openfeature.TransactionContext(ctx))
}

// SetFeatureFlags sets flags for the scope of a test.
func (c *TestClient) SetFeatureFlags(t testing.TestFramework, flags ...FeatureFlag) {
featureFlags := make(map[string]memprovider.InMemoryFlag)

Expand All @@ -81,3 +82,8 @@ func (c *TestClient) SetFeatureFlags(t testing.TestFramework, flags ...FeatureFl
}
provider.UsingFlags(t, featureFlags)
}

// Cleanup deletes the flags bound to the current test and should be executed after each test execution
func (c *TestClient) Cleanup() {
provider.Cleanup()
}
19 changes: 13 additions & 6 deletions pkg/infra/featureflags/testing/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func Test_Parallel_GoroutineA(t *testing.T) {

client := NewTestClient()
client.SetFeatureFlags(t, FlagFoo)
defer client.Cleanup()

barrier1.Wait()
// proceed only when test-a finished the setup of the flag "bar"
Expand All @@ -80,6 +81,7 @@ func Test_Parallel_GoroutineB(t *testing.T) {
// Initialise the Test Client and set up the test flag
client := NewTestClient()
client.SetFeatureFlags(t, FlagBar)
defer client.Cleanup()

barrier2.Wait()

Expand All @@ -89,15 +91,20 @@ func Test_Parallel_GoroutineB(t *testing.T) {
}

func Test_Sequential(t *testing.T) {
client := NewTestClient()

tests := []FeatureFlag{FlagBaz, FlagFoobar}

for _, flag := range tests {
client.SetFeatureFlags(t, flag)
executeTest(t, flag)
}
}

func executeTest(t *testing.T, flag FeatureFlag) {
client := NewTestClient()

client.SetFeatureFlags(t, flag)
defer client.Cleanup()

if !client.IsEnabled(context.Background(), flag.Name) {
t.Fatalf("expected %s to be disabled", flag.Name)
}
if !client.IsEnabled(context.Background(), flag.Name) {
t.Fatalf("expected %s to be disabled", flag.Name)
}
}