Ensure record ID changes are detected in diff

This commit is contained in:
Tobie Morgan Hitchcock 2018-11-29 10:44:17 +00:00
parent 38f0e3469e
commit 3d4081bd54
2 changed files with 12 additions and 3 deletions

View file

@ -277,7 +277,7 @@ func (o *operations) vals(old, now interface{}, path string) {
} }
case *sql.Thing: case *sql.Thing:
nv := now.(*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) o.op("replace", "", path, old, now)
} }
case bool: case bool:

View file

@ -17,11 +17,14 @@ package diff
import ( import (
"testing" "testing"
"github.com/abcum/surreal/sql"
. "github.com/smartystreets/goconvey/convey" . "github.com/smartystreets/goconvey/convey"
) )
var old = map[string]interface{}{ var old = map[string]interface{}{
"age": 18, "age": 18,
"item": sql.NewThing("test", 1),
"name": map[string]interface{}{ "name": map[string]interface{}{
"first": "T", "first": "T",
"last": "M H", "last": "M H",
@ -32,7 +35,8 @@ var old = map[string]interface{}{
} }
var now = map[string]interface{}{ var now = map[string]interface{}{
"age": 29, "age": 29,
"item": sql.NewThing("test", 2),
"name": map[string]interface{}{ "name": map[string]interface{}{
"first": "Tobie", "first": "Tobie",
"last": "Morgan Hitchcock", "last": "Morgan Hitchcock",
@ -97,6 +101,11 @@ var chg = []interface{}{
"path": "/different", "path": "/different",
"value": true, "value": true,
}, },
map[string]interface{}{
"op": "replace",
"path": "/item",
"value": sql.NewThing("test", 2),
},
map[string]interface{}{ map[string]interface{}{
"op": "change", "op": "change",
"path": "/name/first", "path": "/name/first",