MCPcopy
hub / github.com/rs/zerolog / TestCtxDisabled

Function TestCtxDisabled

ctx_test.go:43–74  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

41}
42
43func TestCtxDisabled(t *testing.T) {
44 dl := New(io.Discard).Level(Disabled)
45 ctx := dl.WithContext(context.Background())
46 if ctx != context.Background() {
47 t.Error("WithContext stored a disabled logger")
48 }
49
50 l := New(io.Discard).With().Str("foo", "bar").Logger()
51 ctx = l.WithContext(ctx)
52 if !reflect.DeepEqual(Ctx(ctx), &l) {
53 t.Error("WithContext did not store logger")
54 }
55
56 l.UpdateContext(func(c Context) Context {
57 return c.Str("bar", "baz")
58 })
59 ctx = l.WithContext(ctx)
60 if !reflect.DeepEqual(Ctx(ctx), &l) {
61 t.Error("WithContext did not store updated logger")
62 }
63
64 l = l.Level(DebugLevel)
65 ctx = l.WithContext(ctx)
66 if !reflect.DeepEqual(Ctx(ctx), &l) {
67 t.Error("WithContext did not store copied logger")
68 }
69
70 ctx = dl.WithContext(ctx)
71 if !reflect.DeepEqual(Ctx(ctx), &dl) {
72 t.Error("WithContext did not override logger with a disabled logger")
73 }
74}
75
76type logObjectMarshalerImpl struct {
77 name string

Callers

nothing calls this directly

Calls 9

NewFunction · 0.85
LevelMethod · 0.80
WithContextMethod · 0.80
LoggerMethod · 0.80
WithMethod · 0.80
UpdateContextMethod · 0.80
CtxFunction · 0.70
ErrorMethod · 0.45
StrMethod · 0.45

Tested by

no test coverage detected