captureOutput captures stdout during the execution of fn.
(t *testing.T, fn func())
| 38 | |
| 39 | // captureOutput captures stdout during the execution of fn. |
| 40 | func captureOutput(t *testing.T, fn func()) string { |
| 41 | t.Helper() |
| 42 | old := os.Stdout |
| 43 | r, w, err := os.Pipe() |
| 44 | assert.NoError(t, err) |
| 45 | os.Stdout = w |
| 46 | |
| 47 | fn() |
| 48 | |
| 49 | w.Close() |
| 50 | os.Stdout = old |
| 51 | |
| 52 | var buf bytes.Buffer |
| 53 | buf.ReadFrom(r) |
| 54 | return buf.String() |
| 55 | } |
| 56 | |
| 57 | func TestNewGetCommand_Structure(t *testing.T) { |
| 58 | cmd := NewGetCommand() |
no test coverage detected