DiffJSONMaps compares two JSON maps, optionally printing their differences, and returning true if they are equal.
(t *testing.T, wantMap, gotMap map[string]interface{},
savepath string, quiet bool)
| 51 | // DiffJSONMaps compares two JSON maps, optionally printing their differences, |
| 52 | // and returning true if they are equal. |
| 53 | func DiffJSONMaps(t *testing.T, wantMap, gotMap map[string]interface{}, |
| 54 | savepath string, quiet bool) bool { |
| 55 | sortJSON(wantMap) |
| 56 | sortJSON(gotMap) |
| 57 | |
| 58 | if !reflect.DeepEqual(wantMap, gotMap) { |
| 59 | wantBuf, err := json.MarshalIndent(wantMap, "", " ") |
| 60 | if err != nil { |
| 61 | t.Error("Could not marshal JSON:", err) |
| 62 | } |
| 63 | gotBuf, err := json.MarshalIndent(gotMap, "", " ") |
| 64 | if err != nil { |
| 65 | t.Error("Could not marshal JSON:", err) |
| 66 | } |
| 67 | if !quiet { |
| 68 | t.Errorf("Expected JSON and actual JSON differ:\n%s", |
| 69 | sdiffJSON(wantBuf, gotBuf, savepath, quiet)) |
| 70 | } |
| 71 | return false |
| 72 | } |
| 73 | |
| 74 | return true |
| 75 | } |
| 76 | |
| 77 | // SnipJSON snips the middle of a very long JSON string to make it less than 100 lines |
| 78 | func SnipJSON(buf []byte) string { |
no test coverage detected