| 259 | } |
| 260 | |
| 261 | func TestPipelineCanceled(t *testing.T) { |
| 262 | if runtime.GOOS == "windows" { |
| 263 | t.Skip("FIXME: test skipped on Windows: 'sleep' unavailable") |
| 264 | } |
| 265 | |
| 266 | t.Parallel() |
| 267 | |
| 268 | stdout := &bytes.Buffer{} |
| 269 | |
| 270 | p := pipe.New(pipe.WithStdout(stdout)) |
| 271 | p.Add(pipe.Command("sleep", "10")) |
| 272 | |
| 273 | ctx, cancel := context.WithCancel(context.Background()) |
| 274 | |
| 275 | err := p.Start(ctx) |
| 276 | require.NoError(t, err) |
| 277 | |
| 278 | cancel() |
| 279 | |
| 280 | err = p.Wait() |
| 281 | assert.ErrorIs(t, err, context.Canceled) |
| 282 | } |
| 283 | |
| 284 | // Verify the correct error if a command in the pipeline exits before |
| 285 | // reading all of its predecessor's output. Note that the amount of |