From a1c0529fda732f2c0f88c99810de7cdd035998a8 Mon Sep 17 00:00:00 2001 From: Paulo Truta Date: Sat, 12 Jun 2021 14:24:13 +0000 Subject: [PATCH] Added Example tests with failure status for ExecAndStream --- internal/utils/utils.go | 2 +- internal/utils/utils_test.go | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/internal/utils/utils.go b/internal/utils/utils.go index 16bfa8b..996c0ea 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -27,7 +27,7 @@ func ExecAndStream(path string, command string, args []string) { err := cmd.Run() if err != nil { - log.Fatalf("cmd.Run() failed with %s\n", err) + fmt.Printf("cmd.Run() failed with %s\n", err) } outStr, errStr := string(stdoutBuf.Bytes()), string(stderrBuf.Bytes()) diff --git a/internal/utils/utils_test.go b/internal/utils/utils_test.go index f053514..840985d 100644 --- a/internal/utils/utils_test.go +++ b/internal/utils/utils_test.go @@ -30,6 +30,27 @@ func ExampleExecAndStream() { // err: } +func ExampleExecAndStreamExecutableNotFound() { + ExecAndStream("/", "testcommand", []string{"Hello"}) + // Output: + // cmd.Run() failed with exec: "testcommand": executable file not found in $PATH + // + // out: + // + // err: +} + +func ExampleExecAndStreamError() { + ExecAndStream("/", "man", []string{"Hello"}) + // Output: + // cmd.Run() failed with exit status 16 + // + // out: + // + // err: + // No manual entry for Hello +} + func TestExecAndGetLines(t *testing.T) { testCommand := "echo" testArguments := []string{"$'Line1\nLine2\nLine3'"}