Skip to content

Commit

Permalink
Simplify diff reporting steps in unit test helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
deadlycoconuts committed May 23, 2024
1 parent 2861728 commit 0cd4838
Showing 1 changed file with 1 addition and 16 deletions.
17 changes: 1 addition & 16 deletions api/turing/internal/testutils/validation.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package testutils

import (
"encoding/json"
"fmt"
"reflect"

Expand All @@ -16,21 +15,7 @@ func CompareObjects(actual interface{}, expected interface{}) error {
allowUnexportedOn = reflect.ValueOf(actual).Elem().Interface()
}
if !cmp.Equal(actual, expected, cmp.AllowUnexported(allowUnexportedOn)) {
actualString := fmt.Sprintf("%+v", actual)
expectedString := fmt.Sprintf("%+v", expected)

// Attempt to encode values to JSON, for logging
jsonActual, err := json.Marshal(actual)
if err == nil {
actualString = string(jsonActual)
}
jsonExpected, err := json.Marshal(expected)
if err == nil {
expectedString = string(jsonExpected)
}

return fmt.Errorf("Did not get expected configuration.\nEXPECTED:\n%v\nGOT:\n%v",
expectedString, actualString)
return fmt.Errorf(cmp.Diff(actual, expected, cmp.AllowUnexported(allowUnexportedOn)))
}
return nil
}

0 comments on commit 0cd4838

Please sign in to comment.