Skip to content

Commit

Permalink
add tests for contextuals
Browse files Browse the repository at this point in the history
  • Loading branch information
vahidlazio committed May 22, 2024
1 parent 4eef712 commit f636ad9
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions confidence/confidence.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ type Confidence struct {
}

func (e Confidence) GetContext() map[string]interface{} {
currentMap := e.contextMap
currentMap := map[string]interface{}{}
parentMap := make(map[string]interface{})
if e.parent != nil {
parentMap = e.parent.GetContext()
}
for key, value := range parentMap {
for key, value := range parentMap {
currentMap[key] = value
}
for key, value := range e.contextMap {
currentMap[key] = value
}
return currentMap
Expand Down Expand Up @@ -102,9 +105,18 @@ func (e Confidence) Track(ctx context.Context, eventName string, message map[str
}

func (e Confidence) WithContext(context map[string]interface{}) Confidence {
newMap := map[string]interface{}{}
for key, value := range e.GetContext() {
newMap[key] = value
}

for key, value := range context {
newMap[key] = value
}

return Confidence{
parent: &e,
contextMap: context,
contextMap: newMap,
Config: e.Config,
ResolveClient: e.ResolveClient,
}
Expand Down

0 comments on commit f636ad9

Please sign in to comment.