From 0da8191f60660e4d9ebffdb84ad8aeda46235862 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Mon, 2 Mar 2020 23:43:34 +0800 Subject: [PATCH] Update test helper --- tests/utils.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/utils.go b/tests/utils.go index d12df2dc..292a357d 100644 --- a/tests/utils.go +++ b/tests/utils.go @@ -3,6 +3,7 @@ package tests import ( "reflect" "testing" + "time" ) func AssertEqual(t *testing.T, r, e interface{}, names ...string) { @@ -11,9 +12,18 @@ func AssertEqual(t *testing.T, r, e interface{}, names ...string) { expects := reflect.Indirect(reflect.ValueOf(e)).FieldByName(name).Interface() if !reflect.DeepEqual(got, expects) { - t.Run(name, func(t *testing.T) { - t.Errorf("expects: %v, got %v", expects, got) - }) + got = reflect.Indirect(reflect.ValueOf(got)).Interface() + expects = reflect.Indirect(reflect.ValueOf(got)).Interface() + if curTime, ok := got.(time.Time); ok { + format := "2006-01-02T15:04:05Z07:00" + if curTime.Format(format) != expects.(time.Time).Format(format) { + t.Errorf("expects: %v, got %v", expects.(time.Time).Format(format), curTime.Format(format)) + } + } else { + t.Run(name, func(t *testing.T) { + t.Errorf("expects: %v, got %v", expects, got) + }) + } } } }