MCPcopy Create free account
hub / github.com/Shopify/goose / TestCommandForceKills

Function TestCommandForceKills

shell/shell_test.go:225–253  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

223}
224
225func 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
255func TestCommandStdinBeforeStart(t *testing.T) {
256 ctx := context.Background()

Callers

nothing calls this directly

Calls 9

LenMethod · 0.95
NewBuilderFunction · 0.85
SignalMethod · 0.80
PrepareMethod · 0.65
CmdMethod · 0.65
StartMethod · 0.65
WaitMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected