forked from honeybadger-io/honeybadger-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context_test.go
37 lines (32 loc) · 907 Bytes
/
context_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package honeybadger
import (
"context"
"testing"
)
func TestContextUpdate(t *testing.T) {
c := Context{"foo": "bar"}
c.Update(Context{"foo": "baz"})
if c["foo"] != "baz" {
t.Errorf("Context should update values. expected=%#v actual=%#v", "baz", c["foo"])
}
}
func TestContext(t *testing.T) {
t.Run("setting values is allowed between reads", func(t *testing.T) {
ctx := context.Background()
ctx = Context{"foo": "bar"}.WithContext(ctx)
stored := FromContext(ctx)
if stored == nil {
t.Fatalf("FromContext returned nil")
}
if stored["foo"] != "bar" {
t.Errorf("stored[foo] expected=%q actual=%v", "bar", stored["foo"])
}
// Write a new key then we'll read from the ctx again and make sure it is
// still set.
stored["baz"] = "qux"
stored = FromContext(ctx)
if stored["baz"] != "qux" {
t.Errorf("stored[baz] expected=%q actual=%v", "qux", stored["baz"])
}
})
}