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

Function TestContext_ErrWithStackMarshalerError

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

Source from the content-addressed store, hash-verified

99}
100
101func TestContext_ErrWithStackMarshalerError(t *testing.T) {
102 // Save original
103 original := ErrorStackMarshaler
104 defer func() { ErrorStackMarshaler = original }()
105
106 // Set a mock marshaler that returns an error
107 ErrorStackMarshaler = func(err error) interface{} {
108 return errors.New("stack error")
109 }
110
111 var buf bytes.Buffer
112 log := New(&buf).With().Stack().Err(errors.New("test error")).Logger()
113
114 log.Info().Msg("test message")
115
116 got := decodeIfBinaryToString(buf.Bytes())
117 want := `{"level":"info","stack":"stack error","error":"test error","message":"test message"}` + "\n"
118 if got != want {
119 t.Errorf("Context.Err() with stack marshaler error = %q, want %q", got, want)
120 }
121}
122
123func TestContext_ErrWithStackMarshalerInterface(t *testing.T) {
124 // 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