MCPcopy
hub / github.com/uber-go/zap / TestReplaceGlobals

Function TestReplaceGlobals

global_test.go:40–67  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

38)
39
40func 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
69func TestGlobalsConcurrentUse(t *testing.T) {
70 var (

Callers

nothing calls this directly

Calls 7

LFunction · 0.85
SFunction · 0.85
ReplaceGlobalsFunction · 0.85
AllUntimedMethod · 0.80
withLoggerFunction · 0.70
InfoMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected