From 1c264b1925359d3bf209ad3d37427ab80076a90e Mon Sep 17 00:00:00 2001 From: Harald Nordgren Date: Sat, 24 Mar 2018 20:16:16 +0100 Subject: [PATCH] Refactor ObjectsAreEqual() --- assert/assertions.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/assert/assertions.go b/assert/assertions.go index a5408f5d5..fb1ecff0a 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -54,21 +54,23 @@ type Comparison func() (success bool) // // This function does no assertion of any kind. func ObjectsAreEqual(expected, actual interface{}) bool { - if expected == nil || actual == nil { return expected == actual } - if exp, ok := expected.([]byte); ok { - act, ok := actual.([]byte) - if !ok { - return false - } else if exp == nil || act == nil { - return exp == nil && act == nil - } - return bytes.Equal(exp, act) + + exp, ok := expected.([]byte) + if !ok { + return reflect.DeepEqual(expected, actual) } - 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) } // ObjectsAreEqualValues gets whether two objects are equal, or if their