diffJSONMaps compares two JSON maps, optionally printing their differences, and returning true if they are equal.
(wantMap, gotMap map[string]interface{}, savepath string)
| 77 | // diffJSONMaps compares two JSON maps, optionally printing their differences, |
| 78 | // and returning true if they are equal. |
| 79 | func diffJSONMaps(wantMap, gotMap map[string]interface{}, savepath string) error { |
| 80 | sortJSON(wantMap) |
| 81 | sortJSON(gotMap) |
| 82 | if !reflect.DeepEqual(wantMap, gotMap) { |
| 83 | wantBuf, err := json.MarshalIndent(wantMap, "", " ") |
| 84 | if err != nil { |
| 85 | return errors.Wrap(err, "could not marshal JSON") |
| 86 | } |
| 87 | gotBuf, err := json.MarshalIndent(gotMap, "", " ") |
| 88 | if err != nil { |
| 89 | return errors.Wrap(err, "could not marshal JSON") |
| 90 | } |
| 91 | return errors.Errorf("expected JSON and actual JSON differ:\n%s", |
| 92 | sdiffJSON(wantBuf, gotBuf, savepath)) |
| 93 | } |
| 94 | return nil |
| 95 | } |
| 96 | |
| 97 | func sdiffJSON(wantBuf, gotBuf []byte, savepath string) string { |
| 98 | var wantFile, gotFile *os.File |
no test coverage detected