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

Function TestContext_ErrWithNilStackMarshaler

context_test.go:57–77  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

55}
56
57func TestContext_ErrWithNilStackMarshaler(t *testing.T) {
58 // Save original
59 original := ErrorStackMarshaler
60 defer func() { ErrorStackMarshaler = original }()
61
62 // Set marshaler to return nil
63 ErrorStackMarshaler = func(err error) interface{} {
64 return nil
65 }
66
67 var buf bytes.Buffer
68 log := New(&buf).With().Stack().Err(errors.New("test error")).Logger()
69
70 log.Info().Msg("test message")
71
72 got := decodeIfBinaryToString(buf.Bytes())
73 want := `{"level":"info","message":"test message"}` + "\n" // No stack or error field because stack marshaler returned nil
74 if got != want {
75 t.Errorf("Context.Err() with nil stack marshaler = %q, want %q", got, want)
76 }
77}
78
79func TestContext_ErrWithStackMarshalerObject(t *testing.T) {
80 // Save original

Callers

nothing calls this directly

Calls 9

NewFunction · 0.85
LoggerMethod · 0.80
WithMethod · 0.80
MsgMethod · 0.80
decodeIfBinaryToStringFunction · 0.70
ErrMethod · 0.65
InfoMethod · 0.65
StackMethod · 0.45
BytesMethod · 0.45

Tested by

no test coverage detected