Skip to content

Commit

Permalink
fixup! fixup! move context calculations out of a go routine
Browse files Browse the repository at this point in the history
  • Loading branch information
vahidlazio committed May 22, 2024
1 parent 314dbbb commit c5ebbba
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions confidence/confidence_context_test.go
Original file line number Diff line number Diff line change
@@ -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{}),
}
}

0 comments on commit c5ebbba

Please sign in to comment.