Skip to content

Commit

Permalink
Refactor ObjectsAreEqual()
Browse files Browse the repository at this point in the history
  • Loading branch information
HaraldNordgren authored and ernesto-jimenez committed Jun 9, 2018
1 parent 2a15e20 commit 1c264b1
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions assert/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1c264b1

Please sign in to comment.