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

Function TestSugarPanicLogging

sugar_test.go:442–475  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

440}
441
442func TestSugarPanicLogging(t *testing.T) {
443 tests := []struct {
444 loggerLevel zapcore.Level
445 f func(*SugaredLogger)
446 expectedMsg string
447 }{
448 {FatalLevel, func(s *SugaredLogger) { s.Panic("foo") }, ""},
449 {PanicLevel, func(s *SugaredLogger) { s.Panic("foo") }, "foo"},
450 {DebugLevel, func(s *SugaredLogger) { s.Panic("foo") }, "foo"},
451 {FatalLevel, func(s *SugaredLogger) { s.Panicf("%s", "foo") }, ""},
452 {PanicLevel, func(s *SugaredLogger) { s.Panicf("%s", "foo") }, "foo"},
453 {DebugLevel, func(s *SugaredLogger) { s.Panicf("%s", "foo") }, "foo"},
454 {FatalLevel, func(s *SugaredLogger) { s.Panicw("foo") }, ""},
455 {PanicLevel, func(s *SugaredLogger) { s.Panicw("foo") }, "foo"},
456 {DebugLevel, func(s *SugaredLogger) { s.Panicw("foo") }, "foo"},
457 {FatalLevel, func(s *SugaredLogger) { s.Panicln("foo") }, ""},
458 {PanicLevel, func(s *SugaredLogger) { s.Panicln("foo") }, "foo"},
459 {DebugLevel, func(s *SugaredLogger) { s.Panicln("foo") }, "foo"},
460 }
461
462 for _, tt := range tests {
463 withSugar(t, tt.loggerLevel, nil, func(sugar *SugaredLogger, logs *observer.ObservedLogs) {
464 assert.Panics(t, func() { tt.f(sugar) }, "Expected panic-level logger calls to panic.")
465 if tt.expectedMsg != "" {
466 assert.Equal(t, []observer.LoggedEntry{{
467 Context: []Field{},
468 Entry: zapcore.Entry{Message: tt.expectedMsg, Level: PanicLevel},
469 }}, logs.AllUntimed(), "Unexpected log output.")
470 } else {
471 assert.Equal(t, 0, logs.Len(), "Didn't expect any log output.")
472 }
473 })
474 }
475}
476
477func TestSugarFatalLogging(t *testing.T) {
478 tests := []struct {

Callers

nothing calls this directly

Calls 7

withSugarFunction · 0.85
PanicfMethod · 0.80
PanicwMethod · 0.80
PaniclnMethod · 0.80
AllUntimedMethod · 0.80
PanicMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected