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

Function TestContext_ErrWithStackMarshalerObject

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

Source from the content-addressed store, hash-verified

77}
78
79func TestContext_ErrWithStackMarshalerObject(t *testing.T) {
80 // Save original
81 original := ErrorStackMarshaler
82 defer func() { ErrorStackMarshaler = original }()
83
84 // Set a mock marshaler that returns LogObjectMarshaler
85 ErrorStackMarshaler = func(err error) interface{} {
86 return logObjectMarshalerImpl{name: "user", age: 30}
87 }
88
89 var buf bytes.Buffer
90 log := New(&buf).With().Stack().Err(errors.New("test error")).Logger()
91
92 log.Info().Msg("test message")
93
94 got := decodeIfBinaryToString(buf.Bytes())
95 want := `{"level":"info","stack":{"name":"user","age":-30},"error":"test error","message":"test message"}` + "\n"
96 if got != want {
97 t.Errorf("Context.Err() with stack marshaler object = %q, want %q", got, want)
98 }
99}
100
101func TestContext_ErrWithStackMarshalerError(t *testing.T) {
102 // 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