get things compact
This commit is contained in:
parent
6d27fedf62
commit
80c1195ee1
@ -96,6 +96,7 @@ func AssertEqual(x, y interface{}) bool {
|
|||||||
if x == nil || y == nil {
|
if x == nil || y == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
xval := reflect.ValueOf(x)
|
xval := reflect.ValueOf(x)
|
||||||
yval := reflect.ValueOf(y)
|
yval := reflect.ValueOf(y)
|
||||||
if xval.Kind() == reflect.Ptr && xval.IsNil() ||
|
if xval.Kind() == reflect.Ptr && xval.IsNil() ||
|
||||||
@ -106,7 +107,6 @@ func AssertEqual(x, y interface{}) bool {
|
|||||||
if valuer, ok := x.(driver.Valuer); ok {
|
if valuer, ok := x.(driver.Valuer); ok {
|
||||||
x, _ = valuer.Value()
|
x, _ = valuer.Value()
|
||||||
}
|
}
|
||||||
|
|
||||||
if valuer, ok := y.(driver.Valuer); ok {
|
if valuer, ok := y.(driver.Valuer); ok {
|
||||||
y, _ = valuer.Value()
|
y, _ = valuer.Value()
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,8 @@ package utils
|
|||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"database/sql/driver"
|
"database/sql/driver"
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
"errors"
|
||||||
"math"
|
"math"
|
||||||
"reflect"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -89,32 +87,7 @@ func (n ModifyAt) Value() (driver.Value, error) {
|
|||||||
return n.Time.Unix(), nil
|
return n.Time.Unix(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type datatypesJSON json.RawMessage
|
|
||||||
|
|
||||||
func (j datatypesJSON) Value() (driver.Value, error) {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAssertEqual(t *testing.T) {
|
func TestAssertEqual(t *testing.T) {
|
||||||
type model struct {
|
|
||||||
Raw *datatypesJSON
|
|
||||||
}
|
|
||||||
|
|
||||||
// copied from your code
|
|
||||||
// would be the same as var i1 *datatypesJSON
|
|
||||||
m1 := model{}
|
|
||||||
f1 := reflect.Indirect(reflect.ValueOf(m1)).Field(0)
|
|
||||||
i1 := f1.Interface()
|
|
||||||
|
|
||||||
// copied from your code
|
|
||||||
// would be the same as
|
|
||||||
// k := datatypesJSON("dreggn")
|
|
||||||
// i2 := &k
|
|
||||||
raw := datatypesJSON("dreggn")
|
|
||||||
m2 := model{Raw: &raw}
|
|
||||||
f2 := reflect.Indirect(reflect.ValueOf(m2)).Field(0)
|
|
||||||
i2 := f2.Interface()
|
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
assertEqualTests := []struct {
|
assertEqualTests := []struct {
|
||||||
name string
|
name string
|
||||||
@ -125,7 +98,7 @@ func TestAssertEqual(t *testing.T) {
|
|||||||
{"error not equal", errors.New("1"), errors.New("2"), false},
|
{"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 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 not equal", ModifyAt{Time: now, Valid: true}, ModifyAt{Time: now.Add(time.Second), Valid: true}, false},
|
||||||
{"driver.Valuer equal (ptr to nil ptr)", i1, i2, false},
|
{"driver.Valuer equal (ptr to nil ptr)", (*ModifyAt)(nil), &ModifyAt{}, false},
|
||||||
}
|
}
|
||||||
for _, test := range assertEqualTests {
|
for _, test := range assertEqualTests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user