Skip to content

Commit

Permalink
Fix sending STDOUT and STDERR over output channel
Browse files Browse the repository at this point in the history
  • Loading branch information
mrnugget committed May 5, 2014
1 parent bc3a8c7 commit 4df99e5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions runner.go
Expand Up @@ -58,12 +58,14 @@ func (r *Runner) Run() (<-chan string, error) {
case stdoutline, ok := <-outch:
if !ok {
outch = nil
break
}
r.stdoutbuf.WriteString(stdoutline)
ch <- stdoutline
case stderrline, ok := <-errch:
if !ok {
errch = nil
break
}
ch <- stderrline
}
Expand Down
24 changes: 23 additions & 1 deletion runner_test.go
Expand Up @@ -12,7 +12,29 @@ func (t *TestPipe) Close() (err error) {
return
}

var testInput []byte = []byte{'f', 'o', 'o'}
func TestRun(t *testing.T) {
stdinbuf := &bytes.Buffer{}
template := []string{"echo", "{{}}"}
runner := NewRunner(template, "{{}}", "foobar", stdinbuf)

ch, err := runner.Run()
if err != nil {
t.Errorf("runner.Run() returned an error: %s", err)
}

output := make([]string, 0)
for outputline := range ch {
output = append(output, outputline)
}

if len(output) != 1 {
t.Errorf("output length wrong. expected: %d, actual: %d", 1, len(output))
}

if output[0] != "foobar\n" {
t.Errorf("output wrong. expected: %q, actual: %q", "foobar", output[0])
}
}

func TestStreamOutput(t *testing.T) {
pipe := &TestPipe{bytes.NewBufferString("foo\nbar\n")}
Expand Down

0 comments on commit 4df99e5

Please sign in to comment.