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

Function TestLog

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

Source from the content-addressed store, hash-verified

17)
18
19func TestLog(t *testing.T) {
20 t.Run("empty", func(t *testing.T) {
21 out := &bytes.Buffer{}
22 log := New(out)
23 log.Log().Msg("")
24 if got, want := decodeIfBinaryToString(out.Bytes()), "{}\n"; got != want {
25 t.Errorf("invalid log output:\ngot: %v\nwant: %v", got, want)
26 }
27 })
28
29 t.Run("one-field", func(t *testing.T) {
30 out := &bytes.Buffer{}
31 log := New(out)
32 log.Log().Str("foo", "bar").Msg("")
33 if got, want := decodeIfBinaryToString(out.Bytes()), `{"foo":"bar"}`+"\n"; got != want {
34 t.Errorf("invalid log output:\ngot: %v\nwant: %v", got, want)
35 }
36 })
37
38 t.Run("two-field", func(t *testing.T) {
39 out := &bytes.Buffer{}
40 log := New(out)
41 log.Log().
42 Str("foo", "bar").
43 Int("n", 123).
44 Msg("")
45 if got, want := decodeIfBinaryToString(out.Bytes()), `{"foo":"bar","n":123}`+"\n"; got != want {
46 t.Errorf("invalid log output:\ngot: %v\nwant: %v", got, want)
47 }
48 })
49}
50
51func TestInfo(t *testing.T) {
52 t.Run("empty", func(t *testing.T) {

Callers

nothing calls this directly

Calls 8

NewFunction · 0.85
MsgMethod · 0.80
decodeIfBinaryToStringFunction · 0.70
RunMethod · 0.65
LogMethod · 0.65
BytesMethod · 0.45
StrMethod · 0.45
IntMethod · 0.45

Tested by

no test coverage detected