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:
parent
28aaa129ff
commit
e5abd5e5a6
1 changed files with 9 additions and 1 deletions
|
|
@ -5,10 +5,12 @@ package main
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
|
|
@ -287,9 +289,12 @@ func deleteBlueprint(t *testing.T, bp *blueprint.Blueprint) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func runComposer(t *testing.T, command ...string) []byte {
|
func runComposer(t *testing.T, command ...string) []byte {
|
||||||
|
fmt.Printf("Running composer-cli %s\n", strings.Join(command, " "))
|
||||||
cmd := exec.Command("composer-cli", command...)
|
cmd := exec.Command("composer-cli", command...)
|
||||||
stdout, err := cmd.StdoutPipe()
|
stdout, err := cmd.StdoutPipe()
|
||||||
require.Nilf(t, err, "Could not create command: %v", err)
|
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()
|
err = cmd.Start()
|
||||||
require.Nilf(t, err, "Could not start command: %v", err)
|
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)
|
contents, err := ioutil.ReadAll(stdout)
|
||||||
require.NoError(t, err, "Could not read stdout from command")
|
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()
|
err = cmd.Wait()
|
||||||
require.NoErrorf(t, err, "Command failed: %v", err)
|
require.NoErrorf(t, err, "Command failed (%v): %v", err, string(errcontents))
|
||||||
|
|
||||||
return contents
|
return contents
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue