MCPcopy Index your code
hub / github.com/dgraph-io/dgraph / diffJSONMaps

Function diffJSONMaps

dgraphapi/json.go:79–95  ·  view source on GitHub ↗

diffJSONMaps compares two JSON maps, optionally printing their differences, and returning true if they are equal.

(wantMap, gotMap map[string]interface{}, savepath string)

Source from the content-addressed store, hash-verified

77// diffJSONMaps compares two JSON maps, optionally printing their differences,
78// and returning true if they are equal.
79func 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
97func sdiffJSON(wantBuf, gotBuf []byte, savepath string) string {
98 var wantFile, gotFile *os.File

Callers 1

compareJSONMapsFunction · 0.85

Calls 3

sortJSONFunction · 0.70
sdiffJSONFunction · 0.70
ErrorfMethod · 0.45

Tested by

no test coverage detected