Add option to make execute fail if executions returns an error
@@ -18,6 +18,7 @@ import (
"github.com/spf13/pflag"
"github.com/spf13/viper"
+ "github.com/stretchr/testify/require"
"github.com/vespa-engine/vespa/client/go/util"
)
@@ -27,6 +28,7 @@ type command struct {
stdin io.ReadWriter
args []string
moreArgs []string
+ failTestOnError bool
}
func resetFlag(f *pflag.Flag) {
@@ -76,7 +78,10 @@ func execute(cmd command, t *testing.T, client *mockHttpClient) (string, string)
// Execute command and return output
rootCmd.SetArgs(append(cmd.args, cmd.moreArgs...))
- Execute()
+ err := Execute()
+ if cmd.failTestOnError {
+ require.Nil(t, err)
+ }
return capturedOut.String(), capturedErr.String()
}
