diff --git a/githooks/hooks/githooks_test.go b/githooks/hooks/githooks_test.go index 6961911b..399c9491 100644 --- a/githooks/hooks/githooks_test.go +++ b/githooks/hooks/githooks_test.go @@ -2,6 +2,7 @@ package hooks import ( "fmt" + "os" "slices" "testing" @@ -11,7 +12,12 @@ import ( func TestGithooksCompliesWithGit(t *testing.T) { doc, err := htmlquery.LoadURL("https://git-scm.com/docs/githooks") - assert.NoError(t, err, "Could not load doc.") + if err != nil { + if os.Getenv("CI") != "" { + t.Fatalf("could not load Git hooks documentation in CI: %v", err) + } + t.Skipf("could not load Git hooks documentation: %v", err) + } list := htmlquery.Find(doc, `//h2[@id="_hooks"]/following-sibling::div//h3`) assert.NotEmpty(t, list) diff --git a/githooks/hooks/images_test.go b/githooks/hooks/images_test.go index 6e69a184..6a1e1939 100644 --- a/githooks/hooks/images_test.go +++ b/githooks/hooks/images_test.go @@ -3,6 +3,7 @@ package hooks import ( "io" "os" + "os/exec" "path" "testing" @@ -11,6 +12,25 @@ import ( "github.com/stretchr/testify/assert" ) +func requireDocker(t *testing.T) { + t.Helper() + + if _, err := exec.LookPath("docker"); err != nil { + if os.Getenv("CI") != "" { + t.Fatalf("docker is required in CI: %v", err) + } + t.Skipf("docker is not available: %v", err) + } + + output, err := exec.Command("docker", "info").CombinedOutput() + if err != nil { + if os.Getenv("CI") != "" { + t.Fatalf("docker daemon is required in CI: %v\n%s", err, output) + } + t.Skipf("docker daemon is not available: %v", err) + } +} + func TestLoadImagesConfig(t *testing.T) { file, err := os.CreateTemp("", "image.yaml") assert.NoError(t, err) @@ -69,6 +89,8 @@ images: } func TestUpdateImages(t *testing.T) { + requireDocker(t) + repo, err := os.MkdirTemp("", "repo") assert.NoError(t, err) defer func() { _ = os.RemoveAll(repo) }()