Skip to content

Commit

Permalink
Merge pull request #453 from kool-dev/fix-error-message
Browse files Browse the repository at this point in the history
Improve error message on docker compose check failure
  • Loading branch information
fabriciojs authored Dec 27, 2022
2 parents 8f53b80 + c757807 commit 2d7c2d5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 6 additions & 1 deletion services/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion services/checker/checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand All @@ -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) {
Expand Down

0 comments on commit 2d7c2d5

Please sign in to comment.