diff options
author | Martin Polden <mpolden@mpolden.no> | 2021-09-02 13:47:58 +0200 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2021-09-02 16:54:17 +0200 |
commit | 919655acb1cf95d76ca68376d3f37b94e0b9f997 (patch) | |
tree | 7a7dbb22265f47e9be09e3361165f2c7f2c4d434 /client | |
parent | acc11ef5d8f889bd4e337db12d25e4b30ae72b7b (diff) |
Exit on errors
Diffstat (limited to 'client')
-rw-r--r-- | client/go/cmd/command_tester.go | 5 | ||||
-rw-r--r-- | client/go/cmd/print.go | 5 |
2 files changed, 9 insertions, 1 deletions
diff --git a/client/go/cmd/command_tester.go b/client/go/cmd/command_tester.go index f40594c288e..8a6e4fd9921 100644 --- a/client/go/cmd/command_tester.go +++ b/client/go/cmd/command_tester.go @@ -55,13 +55,16 @@ func execute(cmd command, t *testing.T, client *mockHttpClient) string { } }) + // Do not exit in tests + exitFunc = func(code int) {} + // Capture stdout and execute command var b bytes.Buffer log.SetOutput(&b) rootCmd.SetArgs(append(cmd.args, cmd.moreArgs...)) rootCmd.Execute() out, err := ioutil.ReadAll(&b) - assert.Empty(t, err, "No error") + assert.Nil(t, err, "No error") return string(out) } diff --git a/client/go/cmd/print.go b/client/go/cmd/print.go index b6394dbe340..12e28c70e5f 100644 --- a/client/go/cmd/print.go +++ b/client/go/cmd/print.go @@ -5,13 +5,17 @@ package cmd import ( "fmt" "log" + "os" ) +var exitFunc = os.Exit // To allow overriding Exit in tests + func printErrHint(err error, hints ...string) { printErr(nil, err.Error()) for _, hint := range hints { log.Print(color.Cyan("Hint: "), hint) } + exitFunc(1) } func printErr(err error, msg ...interface{}) { @@ -21,6 +25,7 @@ func printErr(err error, msg ...interface{}) { if err != nil { log.Print(color.Yellow(err)) } + exitFunc(1) } func printSuccess(msg ...interface{}) { |