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

Function TestCommandRunNoWait

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

Source from the content-addressed store, hash-verified

97}
98
99func TestCommandRunNoWait(t *testing.T) {
100 ctx := context.Background()
101 cmd := New(ctx, "bash", "-c", "sleep 0.05; echo -n foo")
102 stdout := &syncBuffer{}
103 c := cmd.Cmd()
104 c.Stdout = stdout
105
106 err := cmd.Start()
107 assert.NoError(t, err)
108
109 assert.Nil(t, c.ProcessState) // No state yet
110 assert.NotEqual(t, 0, c.Process.Pid) // But the process exists
111
112 // No output yet.
113 // Invoking with Run(false) and a Stdout buffer is not really useful.
114 // Consider using the StdoutPipe instead.
115 assert.Equal(t, 0, stdout.Len())
116
117 // One could manually call Wait(), but might as well use Run(true)
118 err = cmd.Wait()
119 assert.NoError(t, err)
120 assert.NotNil(t, c.ProcessState)
121 assert.True(t, c.ProcessState.Success())
122 assert.True(t, c.ProcessState.Exited())
123
124 assert.NoError(t, err)
125 assert.Equal(t, "foo", stdout.String())
126}
127
128func TestCommandRunPipe(t *testing.T) {
129 ctx := context.Background()

Callers

nothing calls this directly

Calls 6

LenMethod · 0.95
StringMethod · 0.95
NewFunction · 0.70
CmdMethod · 0.65
StartMethod · 0.65
WaitMethod · 0.65

Tested by

no test coverage detected