cli-tests: print stderr when cli test fails

When shelling out for a CLI test the error returned from the Start()
command prints the exit code which is not very informative.  Capturing
and printing stderr is a lot more useful.
This commit is contained in:
Achilleas Koutsou 2021-02-23 11:25:35 +01:00 committed by Tom Gundersen
parent 28aaa129ff
commit e5abd5e5a6

View file

@ -5,10 +5,12 @@ package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"strings"
"time"
"github.com/BurntSushi/toml"
@ -287,9 +289,12 @@ func deleteBlueprint(t *testing.T, bp *blueprint.Blueprint) {
}
func runComposer(t *testing.T, command ...string) []byte {
fmt.Printf("Running composer-cli %s\n", strings.Join(command, " "))
cmd := exec.Command("composer-cli", command...)
stdout, err := cmd.StdoutPipe()
require.Nilf(t, err, "Could not create command: %v", err)
stderr, err := cmd.StderrPipe()
require.Nilf(t, err, "Could not create command: %v", err)
err = cmd.Start()
require.Nilf(t, err, "Could not start command: %v", err)
@ -297,8 +302,11 @@ func runComposer(t *testing.T, command ...string) []byte {
contents, err := ioutil.ReadAll(stdout)
require.NoError(t, err, "Could not read stdout from command")
errcontents, err := ioutil.ReadAll(stderr)
require.NoError(t, err, "Could not read stderr from command")
err = cmd.Wait()
require.NoErrorf(t, err, "Command failed: %v", err)
require.NoErrorf(t, err, "Command failed (%v): %v", err, string(errcontents))
return contents
}