mirror of
https://github.com/containers/skopeo.git
synced 2025-09-07 01:30:16 +00:00
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:
27
integration/utils.go
Normal file
27
integration/utils.go
Normal 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
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
Reference in New Issue
Block a user