(t *testing.T, args ...string)
| 149 | } |
| 150 | |
| 151 | func runCobra(t *testing.T, args ...string) (string, error) { |
| 152 | cmd := rootCmd() |
| 153 | |
| 154 | outBytes := bytes.NewBufferString("") |
| 155 | cmd.SetOut(outBytes) |
| 156 | |
| 157 | cmd.SetArgs(args) |
| 158 | err := cmd.Execute() |
| 159 | |
| 160 | out, ioErr := io.ReadAll(outBytes) |
| 161 | require.NoError(t, ioErr, "read stdout") |
| 162 | |
| 163 | return string(out), err |
| 164 | } |
| 165 | |
| 166 | func readBytes(path string) ([]byte, error) { |
| 167 | file, err := os.Open(filepath.Clean(path)) |
no test coverage detected