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

Function TestInfo

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

Source from the content-addressed store, hash-verified

49}
50
51func TestInfo(t *testing.T) {
52 t.Run("empty", func(t *testing.T) {
53 out := &bytes.Buffer{}
54 log := New(out)
55 log.Info().Msg("")
56 if got, want := decodeIfBinaryToString(out.Bytes()), `{"level":"info"}`+"\n"; got != want {
57 t.Errorf("invalid log output:\ngot: %v\nwant: %v", got, want)
58 }
59 })
60
61 t.Run("one-field", func(t *testing.T) {
62 out := &bytes.Buffer{}
63 log := New(out)
64 log.Info().Str("foo", "bar").Msg("")
65 if got, want := decodeIfBinaryToString(out.Bytes()), `{"level":"info","foo":"bar"}`+"\n"; got != want {
66 t.Errorf("invalid log output:\ngot: %v\nwant: %v", got, want)
67 }
68 })
69
70 t.Run("two-field", func(t *testing.T) {
71 out := &bytes.Buffer{}
72 log := New(out)
73 log.Info().
74 Str("foo", "bar").
75 Int("n", 123).
76 Msg("")
77 if got, want := decodeIfBinaryToString(out.Bytes()), `{"level":"info","foo":"bar","n":123}`+"\n"; got != want {
78 t.Errorf("invalid log output:\ngot: %v\nwant: %v", got, want)
79 }
80 })
81}
82
83func TestEmptyLevelFieldName(t *testing.T) {
84 fieldName := LevelFieldName

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected