| 17 | ) |
| 18 | |
| 19 | func 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 | |
| 51 | func TestInfo(t *testing.T) { |
| 52 | t.Run("empty", func(t *testing.T) { |