Created
January 14, 2019 22:22
-
-
Save mizzy/27ba99a420e1c8a4e41a1b038757f000 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
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