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

Function TestContext_ErrWithStackMarshalerInterface

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

Source from the content-addressed store, hash-verified

121}
122
123func TestContext_ErrWithStackMarshalerInterface(t *testing.T) {
124 // Save original
125 original := ErrorStackMarshaler
126 defer func() { ErrorStackMarshaler = original }()
127
128 // Set a mock marshaler that returns an int
129 ErrorStackMarshaler = func(err error) interface{} {
130 return 42
131 }
132
133 var buf bytes.Buffer
134 log := New(&buf).With().Stack().Err(errors.New("test error")).Logger()
135
136 log.Info().Msg("test message")
137
138 got := decodeIfBinaryToString(buf.Bytes())
139 want := `{"level":"info","stack":42,"error":"test error","message":"test message"}` + "\n"
140 if got != want {
141 t.Errorf("Context.Err() with stack marshaler interface = %q, want %q", got, want)
142 }
143}

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