Skip to content

Commit 36abb3c

Browse files
committed
Add stderr vs stdout test
1 parent 19cd199 commit 36abb3c

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

localexec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,6 @@ func (w disabledStdinWriter) Close() error {
134134
return nil
135135
}
136136

137-
func (w disabledStdinWriter) Write(a []byte) (written int, err error) {
137+
func (w disabledStdinWriter) Write(_ []byte) (written int, err error) {
138138
return 0, xerrors.Errorf("stdin is not enabled for this command")
139139
}

localexec_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package wsep
22

33
import (
4+
"bytes"
45
"context"
56
"io"
67
"io/ioutil"
@@ -117,3 +118,32 @@ func TestStdinFail(t *testing.T) {
117118
err = process.Wait()
118119
assert.Success(t, "process wait", err)
119120
}
121+
122+
func TestStdoutVsStderr(t *testing.T) {
123+
ctx, cancel := context.WithCancel(context.Background())
124+
defer cancel()
125+
126+
var (
127+
execer LocalExecer
128+
stdout bytes.Buffer
129+
stderr bytes.Buffer
130+
)
131+
process, err := execer.Start(ctx, Command{
132+
Command: "sh",
133+
Args: []string{"-c", "echo stdout-message; echo 1>&2 stderr-message"},
134+
Stdin: false,
135+
TTY: false,
136+
})
137+
assert.Success(t, "start command", err)
138+
139+
go io.Copy(&stdout, process.Stdout())
140+
go io.Copy(&stderr, process.Stderr())
141+
142+
time.Sleep(time.Second)
143+
err = process.Wait()
144+
assert.Success(t, "wait for process to complete", err)
145+
146+
assert.Equal(t, "stdout", "stdout-message", strings.TrimSpace(stdout.String()))
147+
assert.Equal(t, "stderr", "stderr-message", strings.TrimSpace(stderr.String()))
148+
}
149+

0 commit comments

Comments
 (0)