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

Function TestCommandContextCancels

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

Source from the content-addressed store, hash-verified

200}
201
202func 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
225func TestCommandForceKills(t *testing.T) {
226 ctx, cancel := context.WithCancel(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