Skip to content

Commit 47f4135

Browse files
billfprashantv
authored andcommitted
Validate JSON snippets are not only expected, but valid. (uber-go#146)
Inspired by the review of uber-go#145
1 parent 5620bca commit 47f4135

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

field_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package zap
2222

2323
import (
24+
"encoding/json"
2425
"errors"
2526
"net"
2627
"strings"
@@ -46,6 +47,11 @@ func assertFieldJSON(t testing.TB, expected string, field Field) {
4647
enc := newJSONEncoder()
4748
defer enc.Free()
4849

50+
var out interface{}
51+
err := json.Unmarshal([]byte("{"+expected+"}"), &out)
52+
require.NoError(t, err,
53+
"Expected JSON snippet %q must be valid for use in an object.", expected)
54+
4955
field.AddTo(enc)
5056
assert.Equal(t, expected, string(enc.bytes),
5157
"Unexpected JSON output after applying field %+v.", field)

0 commit comments

Comments
 (0)