(t *testing.T)
| 223 | } |
| 224 | |
| 225 | func TestCommandForceKills(t *testing.T) { |
| 226 | ctx, cancel := context.WithCancel(context.Background()) |
| 227 | cmd := NewBuilder(ctx, "bash", "-c", "trap '' TERM; read; echo -n foo"). |
| 228 | WithContextCancellation(100 * time.Millisecond). |
| 229 | Prepare() |
| 230 | |
| 231 | c := cmd.Cmd() |
| 232 | _, err := c.StdinPipe() |
| 233 | assert.NoError(t, err) |
| 234 | |
| 235 | stdout := &bytes.Buffer{} |
| 236 | c.Stdout = stdout |
| 237 | |
| 238 | err = cmd.Start() |
| 239 | assert.NoError(t, err) |
| 240 | |
| 241 | // give bash time to boot and register the SIGTERM handler |
| 242 | time.Sleep(100 * time.Millisecond) |
| 243 | |
| 244 | cancel() |
| 245 | |
| 246 | err = cmd.Wait() |
| 247 | assert.Equal(t, context.Canceled, err) |
| 248 | ws := cmd.Cmd().ProcessState.Sys().(syscall.WaitStatus) |
| 249 | sig := ws.Signal() |
| 250 | assert.Equal(t, "killed", sig.String()) |
| 251 | |
| 252 | assert.Equal(t, 0, stdout.Len()) |
| 253 | } |
| 254 | |
| 255 | func TestCommandStdinBeforeStart(t *testing.T) { |
| 256 | ctx := context.Background() |
nothing calls this directly
no test coverage detected