MCPcopy
hub / github.com/dgraph-io/dgraph / DiffJSONMaps

Function DiffJSONMaps

testutil/json.go:53–75  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

51// DiffJSONMaps compares two JSON maps, optionally printing their differences,
52// and returning true if they are equal.
53func 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
78func SnipJSON(buf []byte) string {

Callers 3

PollTillPassOrTimeoutFunction · 0.85
CompareJSONMapsFunction · 0.85
EqualJSONFunction · 0.85

Calls 4

sortJSONFunction · 0.70
sdiffJSONFunction · 0.70
ErrorMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected