From 3d4081bd5428da5c8bae03b150ca370a7cf49b20 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Thu, 29 Nov 2018 10:44:17 +0000 Subject: [PATCH] Ensure record ID changes are detected in diff --- util/diff/diff.go | 2 +- util/diff/diff_test.go | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/util/diff/diff.go b/util/diff/diff.go index cec9537b..dea5ba95 100644 --- a/util/diff/diff.go +++ b/util/diff/diff.go @@ -277,7 +277,7 @@ func (o *operations) vals(old, now interface{}, path string) { } case *sql.Thing: nv := now.(*sql.Thing) - if ov.TB != nv.TB && ov.ID != nv.ID { + if ov.TB != nv.TB || ov.ID != nv.ID { o.op("replace", "", path, old, now) } case bool: diff --git a/util/diff/diff_test.go b/util/diff/diff_test.go index 922dca34..2c1b3fb2 100644 --- a/util/diff/diff_test.go +++ b/util/diff/diff_test.go @@ -17,11 +17,14 @@ package diff import ( "testing" + "github.com/abcum/surreal/sql" + . "github.com/smartystreets/goconvey/convey" ) var old = map[string]interface{}{ - "age": 18, + "age": 18, + "item": sql.NewThing("test", 1), "name": map[string]interface{}{ "first": "T", "last": "M H", @@ -32,7 +35,8 @@ var old = map[string]interface{}{ } var now = map[string]interface{}{ - "age": 29, + "age": 29, + "item": sql.NewThing("test", 2), "name": map[string]interface{}{ "first": "Tobie", "last": "Morgan Hitchcock", @@ -97,6 +101,11 @@ var chg = []interface{}{ "path": "/different", "value": true, }, + map[string]interface{}{ + "op": "replace", + "path": "/item", + "value": sql.NewThing("test", 2), + }, map[string]interface{}{ "op": "change", "path": "/name/first",