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

Function TestCtx

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

Source from the content-addressed store, hash-verified

12)
13
14func TestCtx(t *testing.T) {
15 log := New(io.Discard)
16 ctx := log.WithContext(context.Background())
17 log2 := Ctx(ctx)
18 if !reflect.DeepEqual(log, *log2) {
19 t.Error("Ctx did not return the expected logger")
20 }
21
22 // update
23 log = log.Level(InfoLevel)
24 ctx = log.WithContext(ctx)
25 log2 = Ctx(ctx)
26 if !reflect.DeepEqual(log, *log2) {
27 t.Error("Ctx did not return the expected logger")
28 }
29
30 log2 = Ctx(context.Background())
31 if log2 != disabledLogger {
32 t.Error("Ctx did not return the expected logger")
33 }
34
35 DefaultContextLogger = &log
36 t.Cleanup(func() { DefaultContextLogger = nil })
37 log2 = Ctx(context.Background())
38 if log2 != &log {
39 t.Error("Ctx did not return the expected logger")
40 }
41}
42
43func TestCtxDisabled(t *testing.T) {
44 dl := New(io.Discard).Level(Disabled)

Callers

nothing calls this directly

Calls 5

NewFunction · 0.85
WithContextMethod · 0.80
LevelMethod · 0.80
CtxFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected