Skip to content

Instantly share code, notes, and snippets.

@mizzy
Created January 14, 2019 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mizzy/27ba99a420e1c8a4e41a1b038757f000 to your computer and use it in GitHub Desktop.
Save mizzy/27ba99a420e1c8a4e41a1b038757f000 to your computer and use it in GitHub Desktop.
func compare(t *testing.T, actual, expected interface{}) error {
if actual == nil {
return fmt.Errorf("Expected response should include %#v, but actually %#v", expected, actual)
}
a := actual.(map[string]interface{})
for k, v := range expected.(map[string]interface{}) {
switch p := v.(type) {
case int:
v = float64(p)
if a[k] != v {
return fmt.Errorf("Expected response parameter %v should be %#v, but actually %#v", k, v, a[k])
}
case string, bool:
if a[k] != v {
return fmt.Errorf("Expected response parameter %v should be %#v, but actually %#v", k, v, a[k])
}
case []map[string]interface{}:
for i, e := range p {
err := compare(t, a[k].([]interface{})[i], e)
if err != nil {
return err
}
}
case map[string]interface{}:
err := compare(t, a[k], v)
if err != nil {
return err
}
}
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment