Skip to content

Commit 12f8131

Browse files
committed
Verify that json.RawMessage works for non-null values
1 parent 7adfce8 commit 12f8131

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/json_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,21 @@ func TestJSONRawMessage(t *testing.T) {
4242
t.Errorf("jsonb mismatch (-want +got):\n%s", diff)
4343
}
4444
})
45+
t.Run("/stdlib/"+payload, func(t *testing.T) {
46+
var n json.RawMessage
47+
if err := db.QueryRow(fmt.Sprintf(`SELECT '%s'::json`, payload)).Scan(&n); err != nil {
48+
t.Fatal(err)
49+
}
50+
if diff := cmp.Diff(string(json.RawMessage(payload)), string(n)); diff != "" {
51+
t.Errorf("json mismatch (-want +got):\n%s", diff)
52+
}
53+
if err := db.QueryRow(fmt.Sprintf(`SELECT '%s'::jsonb`, payload)).Scan(&n); err != nil {
54+
t.Fatal(err)
55+
}
56+
if diff := cmp.Diff(string(json.RawMessage(payload)), string(n)); diff != "" {
57+
t.Errorf("jsonb mismatch (-want +got):\n%s", diff)
58+
}
59+
})
4560
}
4661
t.Run("NULL", func(t *testing.T) {
4762
var n pqtype.NullRawMessage

0 commit comments

Comments
 (0)