From c5ebbba5eb0778c39161d60483e2fb05c7f2891a Mon Sep 17 00:00:00 2001 From: vahid torkaman Date: Wed, 22 May 2024 12:17:28 +0200 Subject: [PATCH] fixup! fixup! move context calculations out of a go routine --- confidence/confidence_context_test.go | 43 +++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 confidence/confidence_context_test.go diff --git a/confidence/confidence_context_test.go b/confidence/confidence_context_test.go new file mode 100644 index 0000000..9a17a57 --- /dev/null +++ b/confidence/confidence_context_test.go @@ -0,0 +1,43 @@ +package confidence + +import ( + "github.com/stretchr/testify/assert" + "testing" +) + +func TestContextIsInConfidenceObject(t *testing.T) { + client := create_confidence(t, templateResponse()) + client.PutContext("hello", "hey") + assert.Equal(t, client.GetContext(), map[string]interface{}{"hello": "hey"}) +} + +func TestWithContextIsInChildContext(t *testing.T) { + client := create_confidence(t, templateResponse()) + client.PutContext("hello", "hey") + child := client.WithContext(map[string]interface{}{"west": "world"}) + assert.Equal(t, child.GetContext(), map[string]interface{}{"hello": "hey", "west": "world"}) + client.PutContext("hello2", "hey2") + assert.Equal(t, child.GetContext(), map[string]interface{}{"hello": "hey", "west": "world", "hello2": "hey2"}) +} + + +func TestChildContextOverrideParentContext(t *testing.T) { + client := create_confidence(t, templateResponse()) + client.PutContext("hello", "hey") + child := client.WithContext(map[string]interface{}{"hello": "boom"}) + assert.Equal(t, child.GetContext(), map[string]interface{}{"hello": "boom"}) + assert.Equal(t, client.GetContext(), map[string]interface{}{"hello": "hey"}) +} + +func create_confidence(t *testing.T, response ResolveResponse) *Confidence { + config := APIConfig{ + APIKey: "apiKey", + Region: APIRegionGlobal, + } + return &Confidence{ + Config: config, + ResolveClient: MockResolveClient{MockedResponse: response, MockedError: nil, TestingT: t}, + contextMap: make(map[string]interface{}), + } +} +