forked from rs/zerolog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ctx_test.go
47 lines (40 loc) · 1.06 KB
/
ctx_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
38
39
40
41
42
43
44
45
46
47
package zerolog
import (
"context"
"io/ioutil"
"reflect"
"testing"
)
func TestCtx(t *testing.T) {
log := New(ioutil.Discard)
ctx := log.WithContext(context.Background())
log2 := Ctx(ctx)
if !reflect.DeepEqual(log, *log2) {
t.Error("Ctx did not return the expected logger")
}
// update
log = log.Level(InfoLevel)
ctx = log.WithContext(ctx)
log2 = Ctx(ctx)
if !reflect.DeepEqual(log, *log2) {
t.Error("Ctx did not return the expected logger")
}
log2 = Ctx(context.Background())
if log2 != disabledLogger {
t.Error("Ctx did not return the expected logger")
}
}
func TestCtxDisabled(t *testing.T) {
ctx := disabledLogger.WithContext(context.Background())
if ctx != context.Background() {
t.Error("WithContext stored a disabled logger")
}
ctx = New(ioutil.Discard).WithContext(ctx)
if reflect.DeepEqual(Ctx(ctx), disabledLogger) {
t.Error("WithContext did not store logger")
}
ctx = disabledLogger.WithContext(ctx)
if !reflect.DeepEqual(Ctx(ctx), disabledLogger) {
t.Error("WithContext did not update logger pointer with disabled logger")
}
}