Update test helper

This commit is contained in:
Jinzhu 2020-03-02 23:43:34 +08:00
parent 9fcc546a69
commit 0da8191f60
1 changed files with 13 additions and 3 deletions

View File

@ -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)
})
}
}
}
}