From b2d2084a97190370898ba6b3ec61ced1ca55f130 Mon Sep 17 00:00:00 2001 From: Kavindu Dodanduwa Date: Mon, 17 Jul 2023 12:19:08 -0700 Subject: [PATCH] packaging and comparison update Signed-off-by: Kavindu Dodanduwa --- e2e/common_test.go | 20 +++++++++---------- e2e/evaluation_fuzz_test.go | 4 ++-- e2e/evaluation_test.go | 4 ++-- pkg/openfeature/event_executor.go | 9 +++++---- pkg/openfeature/memprovider/README.md | 5 +++++ .../in_memory_provider.go | 2 +- .../in_memory_provider_test.go | 2 +- 7 files changed, 26 insertions(+), 20 deletions(-) create mode 100644 pkg/openfeature/memprovider/README.md rename pkg/openfeature/{testing => memprovider}/in_memory_provider.go (99%) rename pkg/openfeature/{testing => memprovider}/in_memory_provider_test.go (99%) diff --git a/e2e/common_test.go b/e2e/common_test.go index 46898aa8..60875d2f 100644 --- a/e2e/common_test.go +++ b/e2e/common_test.go @@ -2,11 +2,11 @@ package e2e_test import ( "github.com/open-feature/go-sdk/pkg/openfeature" - mp "github.com/open-feature/go-sdk/pkg/openfeature/testing" + "github.com/open-feature/go-sdk/pkg/openfeature/memprovider" ) // ctxFunction is a context based evaluation callback -var ctxFunction = func(this mp.InMemoryFlag, evalCtx openfeature.FlattenedContext) ( +var ctxFunction = func(this memprovider.InMemoryFlag, evalCtx openfeature.FlattenedContext) ( interface{}, openfeature.ProviderResolutionDetail) { defaultValue := this.Variants[this.DefaultVariant] @@ -34,10 +34,10 @@ var ctxFunction = func(this mp.InMemoryFlag, evalCtx openfeature.FlattenedContex } } -var memoryFlags = map[string]mp.InMemoryFlag{ +var memoryFlags = map[string]memprovider.InMemoryFlag{ "boolean-flag": { Key: "boolean-flag", - State: mp.Enabled, + State: memprovider.Enabled, DefaultVariant: "on", Variants: map[string]interface{}{ "on": true, @@ -47,7 +47,7 @@ var memoryFlags = map[string]mp.InMemoryFlag{ }, "string-flag": { Key: "string-flag", - State: mp.Enabled, + State: memprovider.Enabled, DefaultVariant: "greeting", Variants: map[string]interface{}{ "greeting": "hi", @@ -57,7 +57,7 @@ var memoryFlags = map[string]mp.InMemoryFlag{ }, "integer-flag": { Key: "integer-flag", - State: mp.Enabled, + State: memprovider.Enabled, DefaultVariant: "ten", Variants: map[string]interface{}{ "one": 1, @@ -67,7 +67,7 @@ var memoryFlags = map[string]mp.InMemoryFlag{ }, "float-flag": { Key: "float-flag", - State: mp.Enabled, + State: memprovider.Enabled, DefaultVariant: "half", Variants: map[string]interface{}{ "tenth": 0.1, @@ -77,7 +77,7 @@ var memoryFlags = map[string]mp.InMemoryFlag{ }, "object-flag": { Key: "object-flag", - State: mp.Enabled, + State: memprovider.Enabled, DefaultVariant: "template", Variants: map[string]interface{}{ "empty": map[string]interface{}{}, @@ -91,7 +91,7 @@ var memoryFlags = map[string]mp.InMemoryFlag{ }, "wrong-flag": { Key: "wrong-flag", - State: mp.Enabled, + State: memprovider.Enabled, DefaultVariant: "one", Variants: map[string]interface{}{ "one": "uno", @@ -101,7 +101,7 @@ var memoryFlags = map[string]mp.InMemoryFlag{ }, "context-aware": { Key: "context-aware", - State: mp.Enabled, + State: memprovider.Enabled, DefaultVariant: "external", Variants: map[string]interface{}{ "internal": "INTERNAL", diff --git a/e2e/evaluation_fuzz_test.go b/e2e/evaluation_fuzz_test.go index c46a4cd8..c6a199d6 100644 --- a/e2e/evaluation_fuzz_test.go +++ b/e2e/evaluation_fuzz_test.go @@ -3,7 +3,7 @@ package e2e_test import ( "context" "github.com/open-feature/go-sdk/pkg/openfeature" - mp "github.com/open-feature/go-sdk/pkg/openfeature/testing" + "github.com/open-feature/go-sdk/pkg/openfeature/memprovider" "strings" "testing" ) @@ -11,7 +11,7 @@ import ( func setupFuzzClient(f *testing.F) *openfeature.Client { f.Helper() - memoryProvider := mp.NewInMemoryProvider(map[string]mp.InMemoryFlag{}) + memoryProvider := memprovider.NewInMemoryProvider(map[string]memprovider.InMemoryFlag{}) err := openfeature.SetProvider(memoryProvider) if err != nil { f.Errorf("error setting up provider %v", err) diff --git a/e2e/evaluation_test.go b/e2e/evaluation_test.go index b3e7863a..99c38b88 100644 --- a/e2e/evaluation_test.go +++ b/e2e/evaluation_test.go @@ -6,7 +6,7 @@ import ( "fmt" "github.com/cucumber/godog" "github.com/open-feature/go-sdk/pkg/openfeature" - mp "github.com/open-feature/go-sdk/pkg/openfeature/testing" + "github.com/open-feature/go-sdk/pkg/openfeature/memprovider" "strconv" "testing" ) @@ -92,7 +92,7 @@ func initializeEvaluationScenario(ctx *godog.ScenarioContext) { } func aProviderIsRegisteredWithCacheDisabled(ctx context.Context) error { - memoryProvider := mp.NewInMemoryProvider(memoryFlags) + memoryProvider := memprovider.NewInMemoryProvider(memoryFlags) err := openfeature.SetProvider(memoryProvider) if err != nil { diff --git a/pkg/openfeature/event_executor.go b/pkg/openfeature/event_executor.go index 281c4621..6db3d628 100644 --- a/pkg/openfeature/event_executor.go +++ b/pkg/openfeature/event_executor.go @@ -2,6 +2,7 @@ package openfeature import ( "fmt" + "reflect" "sync" "time" @@ -260,7 +261,7 @@ func (e *eventExecutor) startListeningAndShutdownOld(newProvider providerReferen // drop from active references for i, r := range e.activeSubscriptions { - if r == oldReference { + if reflect.DeepEqual(oldReference.featureProvider, r.featureProvider) { e.activeSubscriptions = append(e.activeSubscriptions[:i], e.activeSubscriptions[i+1:]...) } } @@ -355,7 +356,7 @@ func (e *eventExecutor) executeHandler(f func(details EventDetails), event Event // isRunning is a helper till we bump to the latest go version with slices.contains support func isRunning(provider providerReference, activeProviders []providerReference) bool { for _, activeProvider := range activeProviders { - if provider.featureProvider == activeProvider.featureProvider { + if reflect.DeepEqual(activeProvider.featureProvider, provider.featureProvider) { return true } } @@ -365,12 +366,12 @@ func isRunning(provider providerReference, activeProviders []providerReference) // isRunning is a helper to check if given provider is already in use func isBound(provider providerReference, defaultProvider providerReference, namedProviders []providerReference) bool { - if provider.featureProvider == defaultProvider.featureProvider { + if reflect.DeepEqual(provider.featureProvider, defaultProvider.featureProvider) { return true } for _, namedProvider := range namedProviders { - if provider.featureProvider == namedProvider.featureProvider { + if reflect.DeepEqual(provider.featureProvider, namedProvider.featureProvider) { return true } } diff --git a/pkg/openfeature/memprovider/README.md b/pkg/openfeature/memprovider/README.md new file mode 100644 index 00000000..8751e849 --- /dev/null +++ b/pkg/openfeature/memprovider/README.md @@ -0,0 +1,5 @@ +# In-memory provider + +`InMemoryProvider` is an OpenFeature compliant provider implementation with an in-memory flag storage. + +While the main usage of this provider is SDK testing, you may use it for minimal OpenFeature use cases where appropriate. \ No newline at end of file diff --git a/pkg/openfeature/testing/in_memory_provider.go b/pkg/openfeature/memprovider/in_memory_provider.go similarity index 99% rename from pkg/openfeature/testing/in_memory_provider.go rename to pkg/openfeature/memprovider/in_memory_provider.go index 8ad037bf..81bcf5b2 100644 --- a/pkg/openfeature/testing/in_memory_provider.go +++ b/pkg/openfeature/memprovider/in_memory_provider.go @@ -1,4 +1,4 @@ -package testing +package memprovider import ( "context" diff --git a/pkg/openfeature/testing/in_memory_provider_test.go b/pkg/openfeature/memprovider/in_memory_provider_test.go similarity index 99% rename from pkg/openfeature/testing/in_memory_provider_test.go rename to pkg/openfeature/memprovider/in_memory_provider_test.go index 2a4ba66b..48224d04 100644 --- a/pkg/openfeature/testing/in_memory_provider_test.go +++ b/pkg/openfeature/memprovider/in_memory_provider_test.go @@ -1,4 +1,4 @@ -package testing +package memprovider import ( "context"