Skip to content

Commit cebe19d

Browse files
committed
. F add support for general valid JSON types in VerifyJSONBytes
closes #39
1 parent bc946f7 commit cebe19d

10 files changed

+35
-1
lines changed

approvals.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func VerifyJSONStruct(t core.Failable, obj interface{}, opts ...VerifyOptions) {
138138
// VerifyJSONBytes(t, []byte("{ \"Greeting\": \"Hello\" }"))
139139
func VerifyJSONBytes(t core.Failable, bs []byte, opts ...VerifyOptions) {
140140
t.Helper()
141-
var obj map[string]interface{}
141+
var obj interface{}
142142
err := json.Unmarshal(bs, &obj)
143143
if err != nil {
144144
message := fmt.Sprintf("error while parsing JSON\nerror:\n %s\nJSON:\n %s\n", err, string(bs))

approvals_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,26 @@ func TestVerifyJSONBytesWithScrubbedIds(t *testing.T) {
141141
VerifyJSONBytes(t, jsonb, Options().WithScrubber(scrubber))
142142
}
143143

144+
func TestVerifyJSONBytesAcceptsValidJSONTypes(t *testing.T) {
145+
t.Parallel()
146+
for _, tc := range []struct {
147+
json string
148+
}{
149+
{json: "[1, 2, 3]"},
150+
{json: "{\"foo\": \"bar\"}"},
151+
{json: "1"},
152+
{json: "1.0"},
153+
{json: "1.0e10"},
154+
{json: "true"},
155+
{json: "false"},
156+
{json: "null"},
157+
} {
158+
t.Run(tc.json, func(t *testing.T) {
159+
VerifyJSONBytes(t, []byte(tc.json))
160+
})
161+
}
162+
}
163+
144164
func TestVerifyMap(t *testing.T) {
145165
t.Parallel()
146166
m := map[string]string{
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
10000000000
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[
2+
1,
3+
2,
4+
3
5+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
false
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
null
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
true
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"foo": "bar"
3+
}

0 commit comments

Comments
 (0)