(t *testing.T)
| 38 | ) |
| 39 | |
| 40 | func TestReplaceGlobals(t *testing.T) { |
| 41 | initialL := *L() |
| 42 | initialS := *S() |
| 43 | |
| 44 | withLogger(t, DebugLevel, nil, func(l *Logger, logs *observer.ObservedLogs) { |
| 45 | L().Info("no-op") |
| 46 | S().Info("no-op") |
| 47 | assert.Equal(t, 0, logs.Len(), "Expected initial logs to go to default no-op global.") |
| 48 | |
| 49 | defer ReplaceGlobals(l)() |
| 50 | |
| 51 | L().Info("captured") |
| 52 | S().Info("captured") |
| 53 | expected := observer.LoggedEntry{ |
| 54 | Entry: zapcore.Entry{Message: "captured"}, |
| 55 | Context: []Field{}, |
| 56 | } |
| 57 | assert.Equal( |
| 58 | t, |
| 59 | []observer.LoggedEntry{expected, expected}, |
| 60 | logs.AllUntimed(), |
| 61 | "Unexpected global log output.", |
| 62 | ) |
| 63 | }) |
| 64 | |
| 65 | assert.Equal(t, initialL, *L(), "Expected func returned from ReplaceGlobals to restore initial L.") |
| 66 | assert.Equal(t, initialS, *S(), "Expected func returned from ReplaceGlobals to restore initial S.") |
| 67 | } |
| 68 | |
| 69 | func TestGlobalsConcurrentUse(t *testing.T) { |
| 70 | var ( |
nothing calls this directly
no test coverage detected