assert: ObjectsAreEqual: use time.Equal for time.Time type

pull/1466/head
tscales 2023-08-30 18:43:07 -07:00 committed by Olivier Mengué
parent 1ee798c140
commit 34763e0df3
2 changed files with 23 additions and 12 deletions

View File

@ -59,20 +59,25 @@ func ObjectsAreEqual(expected, actual interface{}) bool {
if expected == nil || actual == nil {
return expected == actual
}
exp, ok := expected.([]byte)
if !ok {
switch exp := expected.(type) {
case []byte:
act, ok := actual.([]byte)
if !ok {
return false
}
if exp == nil || act == nil {
return exp == nil && act == nil
}
return bytes.Equal(exp, act)
case time.Time:
act, ok := actual.(time.Time)
if !ok {
return false
}
return exp.Equal(act)
default:
return reflect.DeepEqual(expected, actual)
}
act, ok := actual.([]byte)
if !ok {
return false
}
if exp == nil || act == nil {
return exp == nil && act == nil
}
return bytes.Equal(exp, act)
}
// copyExportedFields iterates downward through nested data structures and creates a copy

View File

@ -148,6 +148,12 @@ func TestObjectsAreEqual(t *testing.T) {
t.Fail()
}
tm := time.Now()
tz := tm.In(time.Local)
if !ObjectsAreEqualValues(tm, tz) {
t.Error("ObjectsAreEqualValues should return true for time.Time objects with different time zones")
}
}
type Nested struct {