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

Function sdiffJSON

testutil/json.go:94–121  ·  view source on GitHub ↗
(wantBuf, gotBuf []byte, savepath string, quiet bool)

Source from the content-addressed store, hash-verified

92}
93
94func sdiffJSON(wantBuf, gotBuf []byte, savepath string, quiet bool) string {
95 var wantFile, gotFile *os.File
96
97 if savepath != "" {
98 _ = os.MkdirAll(filepath.Dir(savepath), 0700)
99 wantFile, _ = os.Create(savepath + ".expected.json")
100 gotFile, _ = os.Create(savepath + ".received.json")
101 } else {
102 wantFile, _ = os.CreateTemp("", "testutil.expected.json.*")
103 defer os.RemoveAll(wantFile.Name())
104 gotFile, _ = os.CreateTemp("", "testutil.expected.json.*")
105 defer os.RemoveAll(gotFile.Name())
106 }
107
108 _ = os.WriteFile(wantFile.Name(), wantBuf, 0600)
109 _ = os.WriteFile(gotFile.Name(), gotBuf, 0600)
110
111 // don't do diff when one side is missing
112 if len(gotBuf) == 0 {
113 return "Got empty response"
114 } else if quiet {
115 return "Not showing diff in quiet mode"
116 }
117
118 out, _ := exec.Command("sdiff", wantFile.Name(), gotFile.Name()).CombinedOutput()
119
120 return string(out)
121}
122
123// sortJSON looks for any arrays in the unmarshalled JSON and sorts them in an
124// arbitrary but deterministic order based on their content.

Callers 1

DiffJSONMapsFunction · 0.70

Calls 3

RemoveAllMethod · 0.80
CreateMethod · 0.65
NameMethod · 0.65

Tested by

no test coverage detected