From 80c1195ee1af32063115387171a5427f2aee97c0 Mon Sep 17 00:00:00 2001 From: mgoeppe Date: Fri, 29 Sep 2023 08:35:39 +0200 Subject: [PATCH] get things compact --- utils/utils.go | 2 +- utils/utils_test.go | 29 +---------------------------- 2 files changed, 2 insertions(+), 29 deletions(-) diff --git a/utils/utils.go b/utils/utils.go index 739869cd..c8fec5b0 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -96,6 +96,7 @@ func AssertEqual(x, y interface{}) bool { if x == nil || y == nil { return false } + xval := reflect.ValueOf(x) yval := reflect.ValueOf(y) if xval.Kind() == reflect.Ptr && xval.IsNil() || @@ -106,7 +107,6 @@ func AssertEqual(x, y interface{}) bool { if valuer, ok := x.(driver.Valuer); ok { x, _ = valuer.Value() } - if valuer, ok := y.(driver.Valuer); ok { y, _ = valuer.Value() } diff --git a/utils/utils_test.go b/utils/utils_test.go index 956876bc..d0486822 100644 --- a/utils/utils_test.go +++ b/utils/utils_test.go @@ -3,10 +3,8 @@ package utils import ( "database/sql" "database/sql/driver" - "encoding/json" "errors" "math" - "reflect" "strings" "testing" "time" @@ -89,32 +87,7 @@ func (n ModifyAt) Value() (driver.Value, error) { return n.Time.Unix(), nil } -type datatypesJSON json.RawMessage - -func (j datatypesJSON) Value() (driver.Value, error) { - return nil, nil -} - 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() assertEqualTests := []struct { name string @@ -125,7 +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)", i1, i2, false}, + {"driver.Valuer equal (ptr to nil ptr)", (*ModifyAt)(nil), &ModifyAt{}, false}, } for _, test := range assertEqualTests { t.Run(test.name, func(t *testing.T) {