From 7b3de0842561fd516ab69ed866bc50c95a48e664 Mon Sep 17 00:00:00 2001 From: Bracken Dawson Date: Sun, 18 Feb 2024 20:43:45 +0000 Subject: [PATCH] Revert "assert: ObjectsAreEqual: use time.Equal for time.Time type" This reverts commit 34763e0df3d560ca247996a0e9291fa919a3abc6. time.Time.Equal only tests that the two instances refer to the same instant, but time.Time also carries zone information, so this caused two non-equal instances to be considered equal. --- assert/assertions.go | 29 ++++++++++++----------------- assert/assertions_test.go | 4 ++-- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/assert/assertions.go b/assert/assertions.go index f8bee4d..753afa4 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -59,25 +59,20 @@ func ObjectsAreEqual(expected, actual interface{}) bool { if expected == nil || actual == nil { return expected == actual } - 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: + + exp, ok := expected.([]byte) + if !ok { 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 diff --git a/assert/assertions_test.go b/assert/assertions_test.go index ead2ff4..6532f9c 100644 --- a/assert/assertions_test.go +++ b/assert/assertions_test.go @@ -148,8 +148,8 @@ 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 - {int(270), int8(14), false}, // should handle overflow/underflow + {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}, {complex128(1e+100 + 1e+100i), complex64(complex(math.Inf(0), math.Inf(0))), false},