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

Function TestWithErr

log_test.go:301–317  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

299}
300
301func TestWithErr(t *testing.T) {
302 var err error = nil
303 out := &bytes.Buffer{}
304 ctx := New(out).With().
305 Fields(map[string]interface{}{
306 "nil": nil,
307 "nilerror": err,
308 "error": errors.New("some error"),
309 "loggable": loggableError{errors.New("loggable")},
310 "non-loggable": nonLoggableError{fmt.Errorf("oops"), 401},
311 })
312 log := ctx.Logger()
313 log.Log().Msg("")
314 if got, want := decodeIfBinaryToString(out.Bytes()), `{"error":"some error","loggable":{"l":"LOGGABLE"},"nil":null,"nilerror":null,"non-loggable":"oops"}`+"\n"; got != want {
315 t.Errorf("invalid log output:\ngot: %v\nwant: %v", got, want)
316 }
317}
318
319func TestFieldsErr(t *testing.T) {
320 var err error = nil

Callers

nothing calls this directly

Calls 8

NewFunction · 0.85
WithMethod · 0.80
LoggerMethod · 0.80
MsgMethod · 0.80
decodeIfBinaryToStringFunction · 0.70
LogMethod · 0.65
FieldsMethod · 0.45
BytesMethod · 0.45

Tested by

no test coverage detected