Last active
March 18, 2016 16:40
-
-
Save brianfoshee/ce32db4ec0e6726d69a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// compareJSON is a lightweight alternative to | |
// https://github.com/onsi/gomega/blob/master/matchers/match_json_matcher.go | |
func compareJSON(actual []byte, expected []byte) error { | |
var aval interface{} | |
var eval interface{} | |
if err := json.Unmarshal(actual, &aval); err != nil { | |
return err | |
} | |
if err := json.Unmarshal(expected, &eval); err != nil { | |
return err | |
} | |
if !reflect.DeepEqual(aval, eval) { | |
var oa, oe bytes.Buffer | |
if err := json.Indent(&oa, actual, "", "\t"); err != nil { | |
return err | |
} | |
if err := json.Indent(&oe, expected, "", "\t"); err != nil { | |
return err | |
} | |
return fmt.Errorf("\nExpected: %s\nActual: %s", oe.Bytes(), oa.Bytes()) | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment