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

Function TestCommandRunPipe

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

Source from the content-addressed store, hash-verified

126}
127
128func TestCommandRunPipe(t *testing.T) {
129 ctx := context.Background()
130 cmd := New(ctx, "bash", "-c", "sleep 0.05; echo -n foo")
131 c := cmd.Cmd()
132
133 pipe, err := c.StdoutPipe()
134 assert.NoError(t, err)
135
136 err = cmd.Start()
137 assert.NoError(t, err)
138
139 // Still no state, even though we have an output, because the command was a fire-and-forget.
140 assert.Nil(t, c.ProcessState) // No state yet
141 assert.NotEqual(t, 0, c.Process.Pid) // But the process exists
142
143 // Calling ReadAll will wait for the pipe to close, so all the output is there.
144 output, err := io.ReadAll(pipe)
145 assert.NoError(t, err)
146 assert.Equal(t, []byte("foo"), output)
147
148 assert.Nil(t, c.ProcessState) // Still no state yet
149
150 err = cmd.Wait()
151 assert.NoError(t, err)
152
153 // The command completed, and we waited it, so we have a processstate.
154 assert.NotNil(t, c.ProcessState)
155 assert.True(t, c.ProcessState.Exited())
156}
157
158func TestCommandRunWaitPipeFails(t *testing.T) {
159 ctx := context.Background()

Callers

nothing calls this directly

Calls 4

NewFunction · 0.70
CmdMethod · 0.65
StartMethod · 0.65
WaitMethod · 0.65

Tested by

no test coverage detected