Skip to content

Commit

Permalink
Cover JSON null and literal null string in unit test case
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <[email protected]>
  • Loading branch information
mattlord committed Dec 22, 2024
1 parent 3a172c0 commit 7dc29b3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
5 changes: 2 additions & 3 deletions go/mysql/binlog/binlog_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func ParseBinaryJSONDiff(data []byte) (sqltypes.Value, error) {
// Can be a JSON null.
js, err := ParseBinaryJSON(data)
if err == nil && js.Type() == json.TypeNull {
return sqltypes.MakeTrusted(sqltypes.Expression, js.MarshalTo(nil)), nil
return sqltypes.MakeTrusted(sqltypes.Expression, js.MarshalSQLTo(nil)), nil
}
return sqltypes.Value{}, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT,
"invalid JSON diff operation: %d", opType)
Expand Down Expand Up @@ -144,8 +144,7 @@ func ParseBinaryJSONDiff(data []byte) (sqltypes.Value, error) {
"cannot read JSON diff value for path %q", path)
}
pos += valueLen
buf := value.MarshalSQLTo(nil)
diff.Write(buf)
diff.Write(value.MarshalSQLTo(nil))
diff.WriteByte(')')
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1667,13 +1667,13 @@ func TestPlayerPartialImages(t *testing.T) {
},
},
{
input: `update src set jd=JSON_SET(jd, '$.idontknow', null) where id = 3`,
input: `update src set jd=JSON_SET(jd, '$.idontknow', null, '$.idontknoweither', 'null') where id = 3`,
output: []string{
"update dst set jd=JSON_INSERT(`jd`, _utf8mb4'$.idontknow', CAST(_utf8mb4'null' as JSON)) where id=3",
"update dst set jd=JSON_INSERT(JSON_INSERT(`jd`, _utf8mb4'$.idontknow', CAST(_utf8mb4'null' as JSON)), _utf8mb4'$.idontknoweither', CAST(JSON_QUOTE(_utf8mb4'null') as JSON)) where id=3",
},
data: [][]string{
{"1", "{\"key1\": \"val1\", \"color\": \"red\", \"years\": 5, \"hobbies\": [\"skiing\", \"video games\", \"hiking\"]}", "blob data"},
{"3", "{\"key3\": \"val3\", \"idontknow\": null}", "blob data3"},
{"3", "{\"key3\": \"val3\", \"idontknow\": null, \"idontknoweither\": \"null\"}", "blob data3"},
{"12", "{\"key2\": \"val2\", \"misc\": \"{\\\"address\\\":\\\"1012 S Park\\\", \\\"town\\\":\\\"Hastings\\\", \\\"state\\\":\\\"MI\\\"}\", \"current\": true}", "newest blob data"},
},
},
Expand Down

0 comments on commit 7dc29b3

Please sign in to comment.