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

Function TestLoggerLogFatal

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

Source from the content-addressed store, hash-verified

403}
404
405func TestLoggerLogFatal(t *testing.T) {
406 for _, tt := range []struct {
407 do func(*Logger)
408 expected string
409 }{
410 {func(logger *Logger) { logger.Check(FatalLevel, "foo").Write() }, "foo"},
411 {func(logger *Logger) { logger.Log(FatalLevel, "bar") }, "bar"},
412 {func(logger *Logger) { logger.Fatal("baz") }, "baz"},
413 } {
414 withLogger(t, DebugLevel, nil, func(logger *Logger, logs *observer.ObservedLogs) {
415 stub := exit.WithStub(func() {
416 tt.do(logger)
417 })
418 assert.True(t, stub.Exited, "Expected Fatal logger call to terminate process.")
419 output := logs.AllUntimed()
420 assert.Equal(t, 1, len(output), "Unexpected number of logs.")
421 assert.Equal(t, 0, len(output[0].Context), "Unexpected context on first log.")
422 assert.Equal(
423 t,
424 zapcore.Entry{Message: tt.expected, Level: FatalLevel},
425 output[0].Entry,
426 "Unexpected output from fatal-level Log.",
427 )
428 })
429 }
430}
431
432func TestLoggerLeveledMethods(t *testing.T) {
433 withLogger(t, DebugLevel, nil, func(logger *Logger, logs *observer.ObservedLogs) {

Callers

nothing calls this directly

Calls 7

WithStubFunction · 0.92
AllUntimedMethod · 0.80
withLoggerFunction · 0.70
WriteMethod · 0.65
CheckMethod · 0.65
LogMethod · 0.45
FatalMethod · 0.45

Tested by

no test coverage detected