(t *testing.T)
| 114 | } |
| 115 | |
| 116 | func 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. |
| 142 | type testLogSpy struct { |
nothing calls this directly
no test coverage detected