Move ConsumeAndLogOutput to integration/utils.go

This will be used also by non-signing tests.

No code changes besides removing the initial capital letter in the
function name; this is a separate commit only to make reviewing of
future changes to this function easier.
This commit is contained in:
Miloslav Trmač
2016-06-22 15:22:47 +02:00
parent a2e9d08e38
commit 2f2a688026
2 changed files with 29 additions and 23 deletions

27
integration/utils.go Normal file
View File

@@ -0,0 +1,27 @@
package main
import (
"io"
"github.com/go-check/check"
)
// consumeAndLogOutput takes (f, err) from an exec.*Pipe(), and causes all output to it to be logged to c.
func consumeAndLogOutput(c *check.C, id string, f io.ReadCloser, err error) {
c.Assert(err, check.IsNil)
go func() {
defer func() {
f.Close()
c.Logf("Output %s: Closed", id)
}()
buf := make([]byte, 0, 1024)
for {
c.Logf("Output %s: waiting", id)
n, err := f.Read(buf)
c.Logf("Output %s: got %d,%#v: %#v", id, n, err, buf[:n])
if n <= 0 {
break
}
}
}()
}