(wantBuf, gotBuf []byte, savepath string)
| 95 | } |
| 96 | |
| 97 | func 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. |
no test coverage detected