From f173714fe2d7218836ddf451997f5908b4f41ffc Mon Sep 17 00:00:00 2001 From: Lars Karlitski Date: Wed, 27 May 2020 10:34:34 +0200 Subject: [PATCH] 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. --- cmd/osbuild-image-tests/main_test.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/cmd/osbuild-image-tests/main_test.go b/cmd/osbuild-image-tests/main_test.go index 80e5bfdb0..a79270490 100644 --- a/cmd/osbuild-image-tests/main_test.go +++ b/cmd/osbuild-image-tests/main_test.go @@ -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