Merge pull request #1537 from stretchr/fix-time-equal

Revert "assert: ObjectsAreEqual: use time.Equal for time.Time type"
pull/1540/head
Bracken 2024-02-19 12:42:59 +00:00 committed by GitHub
commit fef12e7dc3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 19 deletions

View File

@ -59,8 +59,12 @@ func ObjectsAreEqual(expected, actual interface{}) bool {
if expected == nil || actual == nil {
return expected == actual
}
switch exp := expected.(type) {
case []byte:
exp, ok := expected.([]byte)
if !ok {
return reflect.DeepEqual(expected, actual)
}
act, ok := actual.([]byte)
if !ok {
return false
@ -69,15 +73,6 @@ func ObjectsAreEqual(expected, actual interface{}) bool {
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)
}
}
// copyExportedFields iterates downward through nested data structures and creates a copy

View File

@ -148,7 +148,7 @@ func TestObjectsAreEqualValues(t *testing.T) {
{uint32(10), int32(10), true},
{0, nil, false},
{nil, 0, false},
{now, now.In(time.Local), true}, // should be time zone independent
{now, now.In(time.Local), false}, // should not be time zone independent
{int(270), int8(14), false}, // should handle overflow/underflow
{int8(14), int(270), false},
{[]int{270, 270}, []int8{14, 14}, false},