This repository has been archived on 2025-03-30. You can view files and clone it, but cannot push or open issues or pull requests.
bactdb/api/helpers_test.go
2014-10-03 15:52:17 -08:00

25 lines
579 B
Go

package api
import (
"encoding/json"
"fmt"
"reflect"
)
// Helper function that normalizes structs for comparison with reflect.DeepEqual
func normalize(v interface{}) {
j, err := json.Marshal(v)
if err != nil {
panic(fmt.Sprintf("Could not normalize object %+v due to JSON marshalling error: %s", v, err))
}
err = json.Unmarshal(j, v)
if err != nil {
panic(fmt.Sprintf("Could not normalize object %+v due to JSON un-marshalling error: %s", v, err))
}
}
func normalizeDeepEqual(u, v interface{}) bool {
normalize(u)
normalize(v)
return reflect.DeepEqual(u, v)
}