Skip to content

Commit

Permalink
packaging and comparison update
Browse files Browse the repository at this point in the history
Signed-off-by: Kavindu Dodanduwa <[email protected]>
  • Loading branch information
Kavindu-Dodan committed Jul 17, 2023
1 parent f15945a commit a8c2838
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 20 deletions.
20 changes: 10 additions & 10 deletions e2e/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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,
Expand All @@ -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",
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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{}{},
Expand All @@ -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",
Expand All @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions e2e/evaluation_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ 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"
)

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)
Expand Down
4 changes: 2 additions & 2 deletions e2e/evaluation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 5 additions & 4 deletions pkg/openfeature/event_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package openfeature

import (
"fmt"
"reflect"
"sync"
"time"

Expand Down Expand Up @@ -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:]...)
}
}
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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
}
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/openfeature/memprovider/README.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package testing
package memprovider

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package testing
package memprovider

import (
"context"
Expand Down

0 comments on commit a8c2838

Please sign in to comment.