From 54839e87aea04338238a0f14e020e51a247f49a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20K=C3=A4stle?= Date: Thu, 8 Sep 2022 11:44:57 +0200 Subject: [PATCH 1/2] Surround Status Text by braces so it looks nice in IcingaWeb2 --- exit.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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) From bce255e32607c52856eb45d2757988f7a0172005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20K=C3=A4stle?= Date: Thu, 8 Sep 2022 11:54:08 +0200 Subject: [PATCH 2/2] Fix test cases --- cmd/check_example/main_test.go | 9 +++++---- config_test.go | 2 +- exit_test.go | 10 +++++----- 3 files changed, 11 insertions(+), 10 deletions(-) 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_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 }