(t *testing.T)
| 373 | } |
| 374 | |
| 375 | func TestLoggerLogPanic(t *testing.T) { |
| 376 | for _, tt := range []struct { |
| 377 | do func(*Logger) |
| 378 | should bool |
| 379 | expected string |
| 380 | }{ |
| 381 | {func(logger *Logger) { logger.Check(PanicLevel, "foo").Write() }, true, "foo"}, |
| 382 | {func(logger *Logger) { logger.Log(PanicLevel, "bar") }, true, "bar"}, |
| 383 | {func(logger *Logger) { logger.Panic("baz") }, true, "baz"}, |
| 384 | } { |
| 385 | withLogger(t, DebugLevel, nil, func(logger *Logger, logs *observer.ObservedLogs) { |
| 386 | if tt.should { |
| 387 | assert.Panics(t, func() { tt.do(logger) }, "Expected panic") |
| 388 | } else { |
| 389 | assert.NotPanics(t, func() { tt.do(logger) }, "Expected no panic") |
| 390 | } |
| 391 | |
| 392 | output := logs.AllUntimed() |
| 393 | assert.Equal(t, 1, len(output), "Unexpected number of logs.") |
| 394 | assert.Equal(t, 0, len(output[0].Context), "Unexpected context on first log.") |
| 395 | assert.Equal( |
| 396 | t, |
| 397 | zapcore.Entry{Message: tt.expected, Level: PanicLevel}, |
| 398 | output[0].Entry, |
| 399 | "Unexpected output from panic-level Log.", |
| 400 | ) |
| 401 | }) |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | func TestLoggerLogFatal(t *testing.T) { |
| 406 | for _, tt := range []struct { |
nothing calls this directly
no test coverage detected