| 156 | } |
| 157 | |
| 158 | func TestCommandRunWaitPipeFails(t *testing.T) { |
| 159 | ctx := context.Background() |
| 160 | cmd := New(ctx, "bash", "-c", "sleep 0.05; echo -n foo") |
| 161 | c := cmd.Cmd() |
| 162 | |
| 163 | pipe, err := c.StdoutPipe() |
| 164 | assert.NoError(t, err) |
| 165 | |
| 166 | err = cmd.Run() |
| 167 | assert.NoError(t, err) |
| 168 | |
| 169 | // The command completed, and we waited it, so we have a processstate. |
| 170 | assert.NotNil(t, c.ProcessState) |
| 171 | assert.True(t, c.ProcessState.Exited()) |
| 172 | |
| 173 | // Calling ReadAll will wait for the pipe to close, so all the output is there. |
| 174 | _, err = io.ReadAll(pipe) |
| 175 | assert.Error(t, err, "read |0: file already closed") |
| 176 | } |
| 177 | |
| 178 | func TestCommandWithWorkingDir(t *testing.T) { |
| 179 | tempDir := t.TempDir() |