Skip to content

Commit

Permalink
Merge branch 'main' into feat/events
Browse files Browse the repository at this point in the history
# Conflicts:
#	pkg/openfeature/api.go
#	pkg/openfeature/openfeature.go
#	pkg/openfeature/openfeature_test.go
#	pkg/openfeature/provider.go
#	pkg/openfeature/provider_mock_test.go
#	pkg/openfeature/util_test.go
  • Loading branch information
Kavindu-Dodan committed Jun 20, 2023
2 parents 29b6983 + 609af46 commit 1830f83
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
6 changes: 5 additions & 1 deletion pkg/openfeature/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"reflect"
"testing"
"time"

"github.com/golang/mock/gomock"
)
Expand Down Expand Up @@ -911,10 +912,13 @@ func TestSwitchingProvidersMidEvaluationCausesNoImpactToEvaluation(t *testing.T)
// set new provider during initial provider's Before hook
mockProvider1Hook.EXPECT().Before(gomock.Any(), gomock.Any(), gomock.Any()).
DoAndReturn(func(_ context.Context, _ HookContext, _ HookHints) (*EvaluationContext, error) {
err := SetProvider(mockProvider1)
err := SetProvider(mockProvider2)
if err != nil {
return nil, err
}

// wait for initialization
time.Sleep(200 * time.Millisecond)
return nil, nil
})

Expand Down
26 changes: 21 additions & 5 deletions pkg/openfeature/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"reflect"
"testing"
"time"

"github.com/golang/mock/gomock"

Expand Down Expand Up @@ -332,10 +333,11 @@ func TestRequirement_4_3_4(t *testing.T) {
// The `after` stage MUST run after flag resolution occurs. It accepts a `hook context` (required),
// `flag evaluation details` (required) and `hook hints` (optional). It has no return value.
func TestRequirement_4_3_5(t *testing.T) {
defer t.Cleanup(initSingleton)
ctrl := gomock.NewController(t)

t.Run("after hook MUST run after flag resolution occurs", func(t *testing.T) {
defer t.Cleanup(initSingleton)

mockHook := NewMockHook(ctrl)
client := NewClient("test")
mockProvider := NewMockFeatureProvider(ctrl)
Expand Down Expand Up @@ -383,7 +385,6 @@ func TestRequirement_4_3_5(t *testing.T) {
// resolution. It accepts `hook context` (required), `exception` representing what went wrong (required),
// and `hook hints` (optional). It has no return value.
func TestRequirement_4_3_6(t *testing.T) {
defer t.Cleanup(initSingleton)
ctrl := gomock.NewController(t)

flagKey := "foo"
Expand All @@ -392,6 +393,8 @@ func TestRequirement_4_3_6(t *testing.T) {
flatCtx := flattenContext(evalCtx)

t.Run("error hook MUST run when errors are encountered in the before stage", func(t *testing.T) {
defer t.Cleanup(initSingleton)

mockHook := NewMockHook(ctrl)
client := NewClient("test")
mockProvider := NewMockFeatureProvider(ctrl)
Expand All @@ -416,6 +419,8 @@ func TestRequirement_4_3_6(t *testing.T) {
})

t.Run("error hook MUST run when errors are encountered during flag evaluation", func(t *testing.T) {
defer t.Cleanup(initSingleton)

mockHook := NewMockHook(ctrl)
client := NewClient("test")
mockProvider := NewMockFeatureProvider(ctrl)
Expand Down Expand Up @@ -448,6 +453,8 @@ func TestRequirement_4_3_6(t *testing.T) {
})

t.Run("error hook MUST run when errors are encountered during flag evaluation", func(t *testing.T) {
defer t.Cleanup(initSingleton)

mockHook := NewMockHook(ctrl)
client := NewClient("test")
mockProvider := NewMockFeatureProvider(ctrl)
Expand Down Expand Up @@ -490,7 +497,6 @@ func TestRequirement_4_3_6(t *testing.T) {
// The `finally` hook MUST run after the `before`, `after`, and `error` stages. It accepts a `hook context` (required)
// and `hook hints` (optional). There is no return value.
func TestRequirement_4_3_7(t *testing.T) {
defer t.Cleanup(initSingleton)
ctrl := gomock.NewController(t)

flagKey := "foo"
Expand All @@ -499,6 +505,8 @@ func TestRequirement_4_3_7(t *testing.T) {
flatCtx := flattenContext(evalCtx)

t.Run("finally hook MUST run after the before & after stages", func(t *testing.T) {
defer t.Cleanup(initSingleton)

mockHook := NewMockHook(ctrl)
client := NewClient("test")
mockProvider := NewMockFeatureProvider(ctrl)
Expand All @@ -524,6 +532,8 @@ func TestRequirement_4_3_7(t *testing.T) {
})

t.Run("finally hook MUST run after the error stage", func(t *testing.T) {
defer t.Cleanup(initSingleton)

mockHook := NewMockHook(ctrl)
client := NewClient("test")
mockProvider := NewMockFeatureProvider(ctrl)
Expand Down Expand Up @@ -742,7 +752,6 @@ func TestRequirement_4_4_2(t *testing.T) {
// If an error occurs during the evaluation of `before` or `after` hooks, any remaining hooks in the `before` or `after`
// stages MUST NOT be invoked.
func TestRequirement_4_4_6(t *testing.T) {
defer t.Cleanup(initSingleton)
ctrl := gomock.NewController(t)

flagKey := "foo"
Expand All @@ -753,6 +762,8 @@ func TestRequirement_4_4_6(t *testing.T) {
t.Run(
"if an error occurs during the evaluation of before hooks, any remaining before hooks MUST NOT be invoked",
func(t *testing.T) {
defer t.Cleanup(initSingleton)

mockHook1 := NewMockHook(ctrl)
mockHook2 := NewMockHook(ctrl)
client := NewClient("test")
Expand Down Expand Up @@ -783,6 +794,8 @@ func TestRequirement_4_4_6(t *testing.T) {
t.Run(
"if an error occurs during the evaluation of after hooks, any remaining after hooks MUST NOT be invoked",
func(t *testing.T) {
defer t.Cleanup(initSingleton)

mockHook1 := NewMockHook(ctrl)
mockHook2 := NewMockHook(ctrl)
client := NewClient("test")
Expand Down Expand Up @@ -880,7 +893,7 @@ func TestRequirement_4_5_2(t *testing.T) {
if err != nil {
t.Errorf("error setting up provider %v", err)
}

mockProvider.EXPECT().Hooks().AnyTimes()

hookHints := NewHookHints(map[string]interface{}{"foo": "bar"})
Expand Down Expand Up @@ -909,6 +922,9 @@ func TestRequirement_4_5_2(t *testing.T) {
t.Errorf("error setting up provider %v", err)
}

// wait for initialization
time.Sleep(200 * time.Millisecond)

mockProvider.EXPECT().Hooks().AnyTimes()

hookHints := NewHookHints(map[string]interface{}{"foo": "bar"})
Expand Down

0 comments on commit 1830f83

Please sign in to comment.