| 97 | } |
| 98 | |
| 99 | func 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 | |
| 128 | func TestCommandRunPipe(t *testing.T) { |
| 129 | ctx := context.Background() |