captureStatsOutput runs the stats command and captures stdout.
(t *testing.T, args []string)
| 76 | |
| 77 | // captureStatsOutput runs the stats command and captures stdout. |
| 78 | func captureStatsOutput(t *testing.T, args []string) (string, error) { |
| 79 | t.Helper() |
| 80 | |
| 81 | oldStdout := os.Stdout |
| 82 | r, w, _ := os.Pipe() |
| 83 | os.Stdout = w |
| 84 | |
| 85 | err := runStats(statsCmd, args) |
| 86 | |
| 87 | w.Close() |
| 88 | os.Stdout = oldStdout |
| 89 | |
| 90 | var buf bytes.Buffer |
| 91 | buf.ReadFrom(r) |
| 92 | return buf.String(), err |
| 93 | } |
| 94 | |
| 95 | func TestRunStats_JSONOutput(t *testing.T) { |
| 96 | tmpDir := createStatsTestFiles(t) |
no test coverage detected