From 47546703279c06b7af3ddbc211e2fefbc9ace595 Mon Sep 17 00:00:00 2001 From: fabriciojs Date: Tue, 27 Dec 2022 12:20:48 -0300 Subject: [PATCH 1/2] Improve error message on docker compose check failure --- services/checker/checker.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/services/checker/checker.go b/services/checker/checker.go index 356c962f..7a02450f 100644 --- a/services/checker/checker.go +++ b/services/checker/checker.go @@ -3,6 +3,7 @@ package checker import ( "kool-dev/kool/core/builder" "kool-dev/kool/core/shell" + "strings" ) // Checker defines the check kool dependencies method @@ -33,7 +34,11 @@ func (c *DefaultChecker) Check() error { } if _, err := c.shell.Exec(c.dockerComposeCmd); err != nil { - return ErrDockerComposeNotFound + if strings.Contains(strings.ToLower(err.Error()), "is not a docker command") { + return ErrDockerComposeNotFound + } + // anything else, raise the original error + return err } if _, err := c.shell.Exec(c.dockerCmd); err != nil { From c7578070f6d12fc1afe35e64709827a2658e3475 Mon Sep 17 00:00:00 2001 From: fabriciojs Date: Tue, 27 Dec 2022 12:26:16 -0300 Subject: [PATCH 2/2] fix tests --- services/checker/checker_test.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/services/checker/checker_test.go b/services/checker/checker_test.go index 1ae4a8c5..437947ee 100644 --- a/services/checker/checker_test.go +++ b/services/checker/checker_test.go @@ -41,7 +41,7 @@ func TestDockerComposeNotInstalled(t *testing.T) { var c Checker dockerCmd := &builder.FakeCommand{} - dockerComposeCmd := &builder.FakeCommand{MockExecError: errors.New("not installed")} + dockerComposeCmd := &builder.FakeCommand{MockExecError: errors.New("is not a docker command")} s := &shell.FakeShell{} @@ -57,6 +57,12 @@ func TestDockerComposeNotInstalled(t *testing.T) { if !IsDockerComposeNotFoundError(err) { t.Errorf("Expected the message '%s', got '%s'", ErrDockerComposeNotFound.Error(), err.Error()) } + + dockerComposeCmd.MockExecError = errors.New("some other error") + + if err := c.Check(); err == nil || err.Error() != "some other error" { + t.Errorf("Expected the error message 'some other error', got '%v'", err) + } } func TestDockerNotRunning(t *testing.T) {