pkg/testutils: return errors after restoring stdout

Ensures Ginkgo is able to print detailed failure messages instead
of them being captured by the pipe.
This commit is contained in:
Dan Williams 2017-02-27 13:27:19 -06:00
parent 1bc8141105
commit 5a984f0dee

View File

@ -46,13 +46,15 @@ func CmdAddWithResult(cniNetns, cniIfname string, conf []byte, f func() error) (
os.Stdout = w
err = f()
w.Close()
if err != nil {
return nil, nil, err
}
// parse the result
out, err := ioutil.ReadAll(r)
var out []byte
if err == nil {
out, err = ioutil.ReadAll(r)
}
os.Stdout = oldStdout
// Return errors after restoring stdout so Ginkgo will correctly
// emit verbose error information on stdout
if err != nil {
return nil, nil, err
}