Skip to content

Commit

Permalink
Fix serialization on tip
Browse files Browse the repository at this point in the history
  • Loading branch information
Akshay Shah committed May 10, 2016
1 parent ea309a4 commit a27f35a
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions json_encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package zap

import (
"bytes"
"errors"
"io"
"math"
"strings"
Expand All @@ -45,6 +46,12 @@ func withJSONEncoder(f func(*jsonEncoder)) {
enc.Free()
}

type noJSON struct{}

func (nj noJSON) MarshalJSON() ([]byte, error) {
return nil, errors.New("no")
}

func TestJSONAddString(t *testing.T) {
withJSONEncoder(func(enc *jsonEncoder) {
enc.AddString("baz", "bing")
Expand Down Expand Up @@ -177,8 +184,12 @@ func TestJSONAddObject(t *testing.T) {
})

withJSONEncoder(func(enc *jsonEncoder) {
enc.AddObject("nested", map[int]string{42: "yes"})
assertJSON(t, `"foo":"bar","nested":"json: unsupported type: map[int]string"`, enc)
enc.AddObject("nested", noJSON{})
assertJSON(
t,
`"foo":"bar","nested":"json: error calling MarshalJSON for type zap.noJSON: no"`,
enc,
)
})
}

Expand Down

0 comments on commit a27f35a

Please sign in to comment.