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

Function TestEvent_FieldsWithErrorAndStackMarshalerError

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

Source from the content-addressed store, hash-verified

566}
567
568func TestEvent_FieldsWithErrorAndStackMarshalerError(t *testing.T) {
569 // Save original
570 original := ErrorStackMarshaler
571 defer func() { ErrorStackMarshaler = original }()
572
573 // Set a mock marshaler that returns an error
574 ErrorStackMarshaler = func(err error) interface{} {
575 return errors.New("stack error")
576 }
577
578 var buf bytes.Buffer
579 log := New(&buf)
580
581 err := errors.New("test error")
582 log.Log().Stack().Fields([]interface{}{"error", err}).Msg("test message")
583
584 got := buf.String()
585 want := `{"error":"test error","stack":"stack error","message":"test message"}` + "\n"
586 if got != want {
587 t.Errorf("Event.Fields() with error and stack marshaler error = %q, want %q", got, want)
588 }
589}
590
591func TestEvent_FieldsWithErrorAndStackMarshalerInterface(t *testing.T) {
592 // 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