(wantBuf, gotBuf []byte, savepath string, quiet bool)
| 92 | } |
| 93 | |
| 94 | func 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. |
no test coverage detected