aboutsummaryrefslogtreecommitdiff
path: root/jsonmatch/diff_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'jsonmatch/diff_test.go')
-rw-r--r--jsonmatch/diff_test.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/jsonmatch/diff_test.go b/jsonmatch/diff_test.go
index 1a49010..aba2d00 100644
--- a/jsonmatch/diff_test.go
+++ b/jsonmatch/diff_test.go
@@ -409,3 +409,37 @@ func TestArrayOnArrayAction(t *testing.T) {
match = jsonmatch.Array{jsonmatch.Array{1, 2}}
AssertEqual(t, match.DiffAgainst(message), expected)
}
+
+func TestDispatchIntoCustomDiffable(t *testing.T) {
+ message := []byte(`{"name":"data.json","type":"application/json","content":"{\"foo\":1,\"bar\":3}"}`)
+ match := jsonmatch.Object{
+ "name": "data.json",
+ "type": "application/json",
+ "content": jsonWithinJSONString{jsonmatch.Object{
+ "foo": 1,
+ "bar": 2,
+ }},
+ }
+ expected := []jsonmatch.Diff{{
+ Kind: "value mismatch",
+ Pointer: "/content/bar",
+ ExpectedJSON: "2",
+ ActualJSON: "3",
+ }}
+ AssertEqual(t, match.DiffAgainst(message), expected)
+}
+
+// jsonWithinJSONString appears in TestDispatchIntoCustomDiffable.
+type jsonWithinJSONString struct {
+ inner jsonmatch.Diffable
+}
+
+// DiffAgainst implements the DiffAgainst interface.
+func (j jsonWithinJSONString) DiffAgainst(buf []byte) []jsonmatch.Diff {
+ var s string
+ err := json.Unmarshal(buf, &s)
+ if err != nil {
+ panic(err.Error())
+ }
+ return j.inner.DiffAgainst([]byte(s))
+}