MCPcopy
hub / github.com/rs/zerolog / TestFatalDisabled

Function TestFatalDisabled

log_test.go:1034–1055  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1032}
1033
1034func TestFatalDisabled(t *testing.T) {
1035 out := &bytes.Buffer{}
1036 log := New(out).Level(PanicLevel) // Disable FatalLevel
1037
1038 // Set FatalExitFunc to set a flag
1039 var fatalCalled bool
1040 oldFatalExitFunc := FatalExitFunc
1041 FatalExitFunc = func() { fatalCalled = true }
1042 defer func() { FatalExitFunc = oldFatalExitFunc }()
1043
1044 // Call Fatal, which should be disabled, call done, and return nil
1045 e := log.Fatal()
1046 if e != nil {
1047 t.Error("Expected nil event when Fatal is disabled")
1048 }
1049 if !fatalCalled {
1050 t.Error("Expected FatalExitFunc to be called when Fatal is disabled")
1051 }
1052 if out.Len() > 0 {
1053 t.Errorf("Expected no output when Fatal is disabled, got: %s", out.String())
1054 }
1055}
1056
1057func TestPanicDisabled(t *testing.T) {
1058 out := &bytes.Buffer{}

Callers

nothing calls this directly

Calls 5

NewFunction · 0.85
LevelMethod · 0.80
FatalMethod · 0.80
ErrorMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected