Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions internal/check/docker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package check

import (
"context"
"os/exec"
)

type DockerDaemonCheck struct {
runner func() error
}

func (c *DockerDaemonCheck) Name() string {
return "Docker daemon running"
}

func (c *DockerDaemonCheck) Run(_ context.Context) Result {
run := c.runner
if run == nil {
run = func() error {
return exec.Command("docker", "info").Run()
}
}

if err := run(); err != nil {
return Result{
Name: c.Name(),
Status: StatusFail,
Message: "Docker daemon is not running",
Fix: "start Docker and try again",
}
}
return Result{
Name: c.Name(),
Status: StatusPass,
Message: "Docker daemon is running",
}
}
23 changes: 23 additions & 0 deletions internal/check/docker_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package check

import (
"context"
"errors"
"testing"
)

func TestDockerDaemonCheck_Pass(t *testing.T) {
c := &DockerDaemonCheck{runner: func() error { return nil }}
result := c.Run(context.Background())
if result.Status != StatusPass {
t.Errorf("expected pass, got %v: %s", result.Status, result.Message)
}
}

func TestDockerDaemonCheck_Fail(t *testing.T) {
c := &DockerDaemonCheck{runner: func() error { return errors.New("daemon not running") }}
result := c.Run(context.Background())
if result.Status != StatusFail {
t.Errorf("expected fail, got %v", result.Status)
}
}
3 changes: 2 additions & 1 deletion internal/check/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ func Build(stack detector.DetectedStack) []Check {
}
}
if stack.Docker {
// add Docker checks
cs = append(cs, &BinaryCheck{Binary: "docker"})
cs = append(cs, &DockerDaemonCheck{})
}
if stack.Postgres {
// add Postgres checks
Expand Down