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

Function TestTestLoggerErrorOutput

zaptest/logger_test.go:116–139  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

114}
115
116func TestTestLoggerErrorOutput(t *testing.T) {
117 // This test verifies that the test logger logs internal messages to the
118 // testing.T and marks the test as failed.
119
120 ts := newTestLogSpy(t)
121 defer ts.AssertFailed()
122
123 log := NewLogger(ts)
124
125 // Replace with a core that fails.
126 log = log.WithOptions(zap.WrapCore(func(zapcore.Core) zapcore.Core {
127 return zapcore.NewCore(
128 zapcore.NewConsoleEncoder(zap.NewDevelopmentEncoderConfig()),
129 zapcore.Lock(zapcore.AddSync(ztest.FailWriter{})),
130 zapcore.DebugLevel,
131 )
132 }))
133
134 log.Info("foo") // this fails
135
136 if assert.Len(t, ts.Messages, 1, "expected a log message") {
137 assert.Regexp(t, `write error: failed`, ts.Messages[0])
138 }
139}
140
141// testLogSpy is a testing.TB that captures logged messages.
142type testLogSpy struct {

Callers

nothing calls this directly

Calls 12

WithOptionsMethod · 0.95
InfoMethod · 0.95
WrapCoreFunction · 0.92
NewCoreFunction · 0.92
NewConsoleEncoderFunction · 0.92
LockFunction · 0.92
AddSyncFunction · 0.92
newTestLogSpyFunction · 0.85
AssertFailedMethod · 0.80
NewLoggerFunction · 0.70
LenMethod · 0.45

Tested by

no test coverage detected