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

Function TestEvent_FieldsWithErrorAndStackMarshalerObject

event_test.go:545–566  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

543}
544
545func TestEvent_FieldsWithErrorAndStackMarshalerObject(t *testing.T) {
546 // Save original
547 original := ErrorStackMarshaler
548 defer func() { ErrorStackMarshaler = original }()
549
550 // Set a mock marshaler that returns LogObjectMarshaler
551 ErrorStackMarshaler = func(err error) interface{} {
552 return mockLogObjectMarshaler{data: "stack-data"}
553 }
554
555 var buf bytes.Buffer
556 log := New(&buf)
557
558 err := errors.New("test error")
559 log.Log().Stack().Fields([]interface{}{"error", err}).Msg("test message")
560
561 got := buf.String()
562 want := `{"error":"test error","stack":{"stack_func":"stack-data"},"message":"test message"}` + "\n"
563 if got != want {
564 t.Errorf("Event.Fields() with error and stack marshaler object = %q, want %q", got, want)
565 }
566}
567
568func TestEvent_FieldsWithErrorAndStackMarshalerError(t *testing.T) {
569 // Save original

Callers

nothing calls this directly

Calls 6

NewFunction · 0.85
MsgMethod · 0.80
LogMethod · 0.65
FieldsMethod · 0.45
StackMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected