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

Function TestContext_AnErrWithNilErrorMarshal

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

Source from the content-addressed store, hash-verified

33}
34
35func TestContext_AnErrWithNilErrorMarshal(t *testing.T) {
36 // Save original
37 original := ErrorMarshalFunc
38 defer func() { ErrorMarshalFunc = original }()
39
40 // Set marshaler to return a nil error pointer
41 ErrorMarshalFunc = func(err error) interface{} {
42 return (*myError)(nil) // nil pointer of error type
43 }
44
45 var buf bytes.Buffer
46 log := New(&buf).With().AnErr("test", errors.New("some error")).Logger()
47
48 log.Info().Msg("test message")
49
50 got := decodeIfBinaryToString(buf.Bytes())
51 want := `{"level":"info","message":"test message"}` + "\n" // No "test" field because isNilValue returned true
52 if got != want {
53 t.Errorf("Context.AnErr() with nil error marshal = %q, want %q", got, want)
54 }
55}
56
57func TestContext_ErrWithNilStackMarshaler(t *testing.T) {
58 // Save original

Callers

nothing calls this directly

Calls 8

NewFunction · 0.85
LoggerMethod · 0.80
WithMethod · 0.80
MsgMethod · 0.80
decodeIfBinaryToStringFunction · 0.70
InfoMethod · 0.65
AnErrMethod · 0.45
BytesMethod · 0.45

Tested by

no test coverage detected