(t *testing.T)
| 200 | } |
| 201 | |
| 202 | func TestCommandContextCancels(t *testing.T) { |
| 203 | ctx, cancel := context.WithCancel(context.Background()) |
| 204 | cmd := NewBuilder(ctx, "bash", "-c", "read; echo -n foo"). |
| 205 | WithContextCancellation(100 * time.Millisecond). |
| 206 | Prepare() |
| 207 | |
| 208 | c := cmd.Cmd() |
| 209 | stdout := &bytes.Buffer{} |
| 210 | c.Stdout = stdout |
| 211 | |
| 212 | err := cmd.Start() |
| 213 | assert.NoError(t, err) |
| 214 | cancel() |
| 215 | |
| 216 | err = cmd.Wait() |
| 217 | assert.Equal(t, context.Canceled, err) |
| 218 | ws := cmd.Cmd().ProcessState.Sys().(syscall.WaitStatus) |
| 219 | sig := ws.Signal() |
| 220 | assert.Equal(t, "terminated", sig.String()) |
| 221 | |
| 222 | assert.Equal(t, 0, stdout.Len()) |
| 223 | } |
| 224 | |
| 225 | func TestCommandForceKills(t *testing.T) { |
| 226 | ctx, cancel := context.WithCancel(context.Background()) |
nothing calls this directly
no test coverage detected