mirror of
https://github.com/stretchr/testify.git
synced 2025-04-28 13:59:07 +00:00
assert: ObjectsAreEqual: use time.Equal for time.Time type
This commit is contained in:
parent
1ee798c140
commit
34763e0df3
@ -59,12 +59,8 @@ func ObjectsAreEqual(expected, actual interface{}) bool {
|
|||||||
if expected == nil || actual == nil {
|
if expected == nil || actual == nil {
|
||||||
return expected == actual
|
return expected == actual
|
||||||
}
|
}
|
||||||
|
switch exp := expected.(type) {
|
||||||
exp, ok := expected.([]byte)
|
case []byte:
|
||||||
if !ok {
|
|
||||||
return reflect.DeepEqual(expected, actual)
|
|
||||||
}
|
|
||||||
|
|
||||||
act, ok := actual.([]byte)
|
act, ok := actual.([]byte)
|
||||||
if !ok {
|
if !ok {
|
||||||
return false
|
return false
|
||||||
@ -73,6 +69,15 @@ func ObjectsAreEqual(expected, actual interface{}) bool {
|
|||||||
return exp == nil && act == nil
|
return exp == nil && act == nil
|
||||||
}
|
}
|
||||||
return bytes.Equal(exp, act)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// copyExportedFields iterates downward through nested data structures and creates a copy
|
// copyExportedFields iterates downward through nested data structures and creates a copy
|
||||||
|
@ -148,6 +148,12 @@ func TestObjectsAreEqual(t *testing.T) {
|
|||||||
t.Fail()
|
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 {
|
type Nested struct {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user