(t *testing.T)
| 12 | ) |
| 13 | |
| 14 | func 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 | |
| 43 | func TestCtxDisabled(t *testing.T) { |
| 44 | dl := New(io.Discard).Level(Disabled) |
nothing calls this directly
no test coverage detected