mirror of
https://github.com/containers/skopeo.git
synced 2025-09-08 01:59:41 +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:
@@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -35,26 +34,6 @@ func findFingerprint(lineBytes []byte) (string, error) {
|
||||
return "", errors.New("No fingerprint found")
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func (s *SigningSuite) SetUpTest(c *check.C) {
|
||||
_, err := exec.LookPath(skopeoBinary)
|
||||
c.Assert(err, check.IsNil)
|
||||
@@ -67,9 +46,9 @@ func (s *SigningSuite) SetUpTest(c *check.C) {
|
||||
stdin, err := cmd.StdinPipe()
|
||||
c.Assert(err, check.IsNil)
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
ConsumeAndLogOutput(c, "gen-key stdout", stdout, err)
|
||||
consumeAndLogOutput(c, "gen-key stdout", stdout, err)
|
||||
stderr, err := cmd.StderrPipe()
|
||||
ConsumeAndLogOutput(c, "gen-key stderr", stderr, err)
|
||||
consumeAndLogOutput(c, "gen-key stderr", stderr, err)
|
||||
err = cmd.Start()
|
||||
c.Assert(err, check.IsNil)
|
||||
_, err = stdin.Write([]byte("Key-Type: RSA\nName-Real: Testing user\n%commit\n"))
|
||||
|
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