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

Function TestLoggerLogPanic

logger_test.go:375–403  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

373}
374
375func 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
405func TestLoggerLogFatal(t *testing.T) {
406 for _, tt := range []struct {

Callers

nothing calls this directly

Calls 6

AllUntimedMethod · 0.80
withLoggerFunction · 0.70
WriteMethod · 0.65
CheckMethod · 0.65
LogMethod · 0.45
PanicMethod · 0.45

Tested by

no test coverage detected