test/image: also capture osbuild's standard error
Treating stdout and stderr separately makes it hard to match what happened when. It's also easy to miss when `-v` is passed to the test binary. Print the output to stdout when osbuild fails, because the test framework we're using does not print errors if they're too large. Also, don't special-case exec.ExitError. Output might be useful in any case.
This commit is contained in:
parent
0a7c97c97a
commit
f173714fe2
1 changed files with 3 additions and 8 deletions
|
|
@ -53,20 +53,15 @@ func runOsbuild(manifest []byte, outputDirectory string) error {
|
|||
|
||||
cmd := constants.GetOsbuildCommand(outputDirectory)
|
||||
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Stdin = bytes.NewReader(manifest)
|
||||
var outBuffer bytes.Buffer
|
||||
cmd.Stdout = &outBuffer
|
||||
cmd.Stderr = &outBuffer
|
||||
|
||||
err := cmd.Run()
|
||||
|
||||
if err != nil {
|
||||
if _, ok := err.(*exec.ExitError); ok {
|
||||
var formattedOutput bytes.Buffer
|
||||
_ = json.Indent(&formattedOutput, outBuffer.Bytes(), "", " ")
|
||||
return fmt.Errorf("running osbuild failed: %s", formattedOutput.String())
|
||||
}
|
||||
return fmt.Errorf("running osbuild failed from an unexpected reason: %#v", err)
|
||||
fmt.Println(outBuffer.String())
|
||||
return fmt.Errorf("running osbuild failed: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue