mirror of https://github.com/go-gorm/gorm.git
*datatypes.JSON in model causes panic on tx.Statement.Changed (#6611)
* do not panic on nil * more explanation in comments * get things compact
This commit is contained in:
parent
9d8a5bb208
commit
12ba285a52
|
@ -89,19 +89,28 @@ func Contains(elems []string, elem string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func AssertEqual(src, dst interface{}) bool {
|
||||
if !reflect.DeepEqual(src, dst) {
|
||||
if valuer, ok := src.(driver.Valuer); ok {
|
||||
src, _ = valuer.Value()
|
||||
}
|
||||
|
||||
if valuer, ok := dst.(driver.Valuer); ok {
|
||||
dst, _ = valuer.Value()
|
||||
}
|
||||
|
||||
return reflect.DeepEqual(src, dst)
|
||||
func AssertEqual(x, y interface{}) bool {
|
||||
if reflect.DeepEqual(x, y) {
|
||||
return true
|
||||
}
|
||||
return true
|
||||
if x == nil || y == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
xval := reflect.ValueOf(x)
|
||||
yval := reflect.ValueOf(y)
|
||||
if xval.Kind() == reflect.Ptr && xval.IsNil() ||
|
||||
yval.Kind() == reflect.Ptr && yval.IsNil() {
|
||||
return false
|
||||
}
|
||||
|
||||
if valuer, ok := x.(driver.Valuer); ok {
|
||||
x, _ = valuer.Value()
|
||||
}
|
||||
if valuer, ok := y.(driver.Valuer); ok {
|
||||
y, _ = valuer.Value()
|
||||
}
|
||||
return reflect.DeepEqual(x, y)
|
||||
}
|
||||
|
||||
func ToString(value interface{}) string {
|
||||
|
|
|
@ -98,6 +98,7 @@ func TestAssertEqual(t *testing.T) {
|
|||
{"error not equal", errors.New("1"), errors.New("2"), false},
|
||||
{"driver.Valuer equal", ModifyAt{Time: now, Valid: true}, ModifyAt{Time: now, Valid: true}, true},
|
||||
{"driver.Valuer not equal", ModifyAt{Time: now, Valid: true}, ModifyAt{Time: now.Add(time.Second), Valid: true}, false},
|
||||
{"driver.Valuer equal (ptr to nil ptr)", (*ModifyAt)(nil), &ModifyAt{}, false},
|
||||
}
|
||||
for _, test := range assertEqualTests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue