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

Function TestCommandStdinAfterStart

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

Source from the content-addressed store, hash-verified

273}
274
275func TestCommandStdinAfterStart(t *testing.T) {
276 ctx := context.Background()
277 cmd := New(ctx, "bash", "-c", "cat; echo -n foo")
278
279 c := cmd.Cmd()
280 stdin, err := c.StdinPipe()
281 assert.NoError(t, err)
282
283 stdout := &bytes.Buffer{}
284 c.Stdout = stdout
285
286 err = cmd.Start()
287 assert.NoError(t, err)
288
289 _, err = stdin.Write([]byte("bar"))
290 assert.NoError(t, err)
291
292 done := make(chan error)
293 go func() {
294 done <- cmd.Wait()
295 }()
296 time.Sleep(100 * time.Millisecond)
297
298 select {
299 case <-done:
300 assert.Fail(t, "should not be done")
301 default:
302 }
303
304 err = stdin.Close()
305 assert.NoError(t, err)
306
307 err = <-done
308 assert.NoError(t, err)
309
310 assert.Equal(t, "barfoo", stdout.String())
311}
312
313// Verify we can stream while command is running
314func TestCommandStdoutPipe(t *testing.T) {

Callers

nothing calls this directly

Calls 7

StringMethod · 0.95
CloseMethod · 0.80
NewFunction · 0.70
CmdMethod · 0.65
StartMethod · 0.65
WaitMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected