Skip to content

Commit 33fd768

Browse files
committed
rename files for consistent
Signed-off-by: Roman Dmytrenko <rdmytrenko@gmail.com>
1 parent 9f1ffac commit 33fd768

File tree

8 files changed

+51
-70
lines changed

8 files changed

+51
-70
lines changed

README.md

Lines changed: 3 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ client.Boolean(tCtx, ....)
335335
### Multi-Provider Implementation
336336

337337
Included with this SDK is an _experimental_ multi-provider that can be used to query multiple feature flag providers simultaneously.
338-
More information can be found in the [multi package's README](openfeature/multi/README.md).
338+
More information can be found in the [multi package's README](providers/multi/README.md).
339339

340340
## Extending
341341

@@ -449,72 +449,8 @@ func (h MyHook) Error(context context.Context, hookContext openfeature.HookConte
449449
## Testing
450450

451451
The SDK provides a `testing.NewProvider` which allows you to set flags for the scope of a test.
452-
The `TestProvider` is thread-safe and can be used in tests that run in parallel.
453-
454-
Call `testProvider.UsingFlags(t, tt.flags)` to set flags for a test, and clean them up with `testProvider.Cleanup()`
455-
456-
```go
457-
import (
458-
"go.openfeature.dev/openfeature/v2"
459-
"go.openfeature.dev/openfeature/v2/providers/inmemory"
460-
"go.openfeature.dev/openfeature/v2/providers/testing"
461-
)
462-
463-
testProvider := testing.NewProvider()
464-
err := openfeature.SetProviderAndWait(t.Context(), testProvider)
465-
if err != nil {
466-
t.Errorf("unable to set provider")
467-
}
468-
469-
// configure flags for this test suite
470-
tests := map[string]struct {
471-
flags map[string]inmemory.InMemoryFlag
472-
want bool
473-
}{
474-
"test when flag is true": {
475-
flags: map[string]inmemory.InMemoryFlag{
476-
"my_flag": {
477-
State: inmemory.Enabled,
478-
DefaultVariant: "on",
479-
Variants: map[string]any{
480-
"on": true,
481-
},
482-
},
483-
},
484-
want: true,
485-
},
486-
"test when flag is false": {
487-
flags: map[string]inmemory.InMemoryFlag{
488-
"my_flag": {
489-
State: inmemory.Enabled,
490-
DefaultVariant: "off",
491-
Variants: map[string]any{
492-
"off": false,
493-
},
494-
},
495-
},
496-
want: false,
497-
},
498-
}
499-
500-
for name, tt := range tests {
501-
tt := tt
502-
name := name
503-
t.Run(name, func(t *testing.T) {
504-
505-
// be sure to clean up your flags
506-
defer testProvider.Cleanup()
507-
testProvider.UsingFlags(t, tt.flags)
508-
509-
// your code under test
510-
got := functionUnderTest()
511-
512-
if got != tt.want {
513-
t.Fatalf("uh oh, value is not as expected: got %v, want %v", got, tt.want)
514-
}
515-
})
516-
}
517-
```
452+
The `TestProvider` has proper isolation and can be used in tests that run in parallel.
453+
More information can be found in the [testing package's README](providers/testing/README.md).
518454

519455
### Mocks
520456

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Package memprovider provides an in-memory feature flag provider for OpenFeature.
2-
package memprovider
1+
// Package inmemory provides an in-memory feature flag provider for OpenFeature.
2+
package inmemory
33

44
import (
55
"context"

providers/inmemory/in_memory_provider_test.go renamed to providers/inmemory/inmemory_provider_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package memprovider
1+
package inmemory
22

33
import (
44
"math"

providers/testing/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Testing provider
2+
3+
`TestProvider` is an OpenFeature compliant provider implementation designed for testing applications with feature flags.
4+
5+
The testing provider allows you to define feature flag values scoped to individual tests, ensuring test isolation and preventing flag state from leaking between tests. It uses the `InMemoryProvider` internally with per-test flag storage.
6+
7+
# Usage
8+
9+
```go
10+
import (
11+
"testing"
12+
13+
"go.openfeature.dev/openfeature/v2"
14+
"go.openfeature.dev/openfeature/v2/providers/inmemory"
15+
"go.openfeature.dev/openfeature/v2/providers/testing"
16+
)
17+
18+
testProvider := testing.NewProvider()
19+
err := openfeature.SetProviderAndWait(t.Context(), testProvider)
20+
if err != nil {
21+
t.Fatal(err)
22+
}
23+
24+
ctx := testProvider.UsingFlags(t, map[string]memprovider.InMemoryFlag{
25+
"my_feature": {
26+
State: memprovider.Enabled,
27+
DefaultVariant: "on",
28+
Variants: map[string]any{"on": true},
29+
},
30+
})
31+
32+
client := openfeature.NewClient()
33+
result := client.Boolean(ctx, "my_feature", false, openfeature.EvaluationContext{})
34+
```
35+
36+
The testing provider supports parallel test execution with proper isolation.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"runtime"
88
"sync"
9+
"testing"
910

1011
"go.openfeature.dev/openfeature/v2"
1112
memprovider "go.openfeature.dev/openfeature/v2/providers/inmemory"
@@ -43,6 +44,14 @@ func (tp TestProvider) UsingFlags(test TestFramework, flags map[string]memprovid
4344
if ctx == nil {
4445
ctx = context.Background()
4546
}
47+
48+
// if test is testing.TB add the auto Cleanup
49+
if t, ok := test.(testing.TB); ok {
50+
t.Cleanup(func() {
51+
tp.Cleanup(ctx)
52+
})
53+
}
54+
4655
return context.WithValue(ctx, testNameKey, test.Name())
4756
}
4857

0 commit comments

Comments
 (0)