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

Function sdiffJSON

dgraphapi/json.go:97–121  ·  view source on GitHub ↗
(wantBuf, gotBuf []byte, savepath string)

Source from the content-addressed store, hash-verified

95}
96
97func sdiffJSON(wantBuf, gotBuf []byte, savepath string) string {
98 var wantFile, gotFile *os.File
99
100 if savepath != "" {
101 _ = os.MkdirAll(filepath.Dir(savepath), 0700)
102 wantFile, _ = os.Create(savepath + ".expected.json")
103 gotFile, _ = os.Create(savepath + ".received.json")
104 } else {
105 wantFile, _ = os.CreateTemp("", "testutil.expected.json.*")
106 defer os.RemoveAll(wantFile.Name())
107 gotFile, _ = os.CreateTemp("", "testutil.expected.json.*")
108 defer os.RemoveAll(gotFile.Name())
109 }
110
111 _ = os.WriteFile(wantFile.Name(), wantBuf, 0600)
112 _ = os.WriteFile(gotFile.Name(), gotBuf, 0600)
113
114 // don't do diff when one side is missing
115 if len(gotBuf) == 0 {
116 return "Got empty response"
117 }
118
119 out, _ := exec.Command("sdiff", wantFile.Name(), gotFile.Name()).CombinedOutput()
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