diff --git a/cmd/check_example/main_test.go b/cmd/check_example/main_test.go index 42bdbaf..247693a 100644 --- a/cmd/check_example/main_test.go +++ b/cmd/check_example/main_test.go @@ -1,11 +1,12 @@ package main import ( - "github.com/NETWAYS/go-check/testhelper" - "github.com/stretchr/testify/assert" "os" "regexp" "testing" + + "github.com/NETWAYS/go-check/testhelper" + "github.com/stretchr/testify/assert" ) func TestMyMain(t *testing.T) { @@ -13,10 +14,10 @@ func TestMyMain(t *testing.T) { assert.Regexp(t, regexp.MustCompile(`would exit with code 3`), stdout) stdout = testhelper.RunMainTest(main, "--warning", "20") - assert.Regexp(t, regexp.MustCompile(`^OK - value is 10\nwould exit with code 0\n$`), stdout) + assert.Regexp(t, regexp.MustCompile(`^\[OK\] - value is 10\nwould exit with code 0\n$`), stdout) stdout = testhelper.RunMainTest(main, "--warning", "10", "--value", "11") - assert.Regexp(t, regexp.MustCompile(`^WARNING - value is 11\nwould exit with code 1\n$`), stdout) + assert.Regexp(t, regexp.MustCompile(`^\[WARNING\] - value is 11\nwould exit with code 1\n$`), stdout) } func TestMain(m *testing.M) { diff --git a/config_test.go b/config_test.go index d7db1ac..9ad843e 100644 --- a/config_test.go +++ b/config_test.go @@ -14,6 +14,6 @@ func ExampleConfig() { Exitf(OK, "Everything is fine - answer=%d", 42) - // Output: OK - Everything is fine - answer=42 + // Output: [OK] - Everything is fine - answer=42 // would exit with code 0 } diff --git a/exit.go b/exit.go index 777f092..604ec63 100644 --- a/exit.go +++ b/exit.go @@ -2,11 +2,12 @@ package check import ( "fmt" - "github.com/mitchellh/go-ps" "os" "runtime/debug" "strconv" "strings" + + "github.com/mitchellh/go-ps" ) // AllowExit lets you disable the call to os.Exit() in ExitXxx() functions of this package. @@ -34,7 +35,7 @@ func Exitf(rc int, output string, args ...interface{}) { func ExitRaw(rc int, output ...string) { var text strings.Builder - text.WriteString(StatusText(rc) + " -") + text.WriteString("[" + StatusText(rc) + "] -") for _, s := range output { text.WriteString(" " + s) diff --git a/exit_test.go b/exit_test.go index e74dfeb..55835b1 100644 --- a/exit_test.go +++ b/exit_test.go @@ -8,26 +8,26 @@ import ( func ExampleExit() { Exitf(OK, "Everything is fine - value=%d", 42) - // Output: OK - Everything is fine - value=42 + // Output: [OK] - Everything is fine - value=42 // would exit with code 0 } func ExampleExitf() { Exitf(OK, "Everything is fine - value=%d", 42) - // Output: OK - Everything is fine - value=42 + // Output: [OK] - Everything is fine - value=42 // would exit with code 0 } func ExampleExitRaw() { ExitRaw(OK, "Everything is fine") - // Output: OK - Everything is fine + // Output: [OK] - Everything is fine // would exit with code 0 } func ExampleExitError() { err := fmt.Errorf("connection to %s has been timed out", "localhost:12345") ExitError(err) - // Output: UNKNOWN - connection to localhost:12345 has been timed out (*errors.errorString) + // Output: [UNKNOWN] - connection to localhost:12345 has been timed out (*errors.errorString) // would exit with code 3 } @@ -35,7 +35,7 @@ func ExampleCatchPanic() { defer CatchPanic() panic("something bad happened") - // Output: UNKNOWN - Golang encountered a panic: something bad happened + // Output: [UNKNOWN] - Golang encountered a panic: something bad happened // would exit with code 3 }