Skip to content

Commit 4c83225

Browse files
Ajit Pratap Singhclaude
authored andcommitted
fix(schema): skip testcontainers tests when Docker is unavailable
Add runtime Docker availability check (docker info) before attempting to create testcontainers. This prevents test failures on macOS CI runners that don't have Docker installed, without requiring -short flag. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 35eea06 commit 4c83225

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

pkg/schema/mysql/loader_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"context"
1919
"database/sql"
2020
"fmt"
21+
"os/exec"
2122
"testing"
2223
"time"
2324

@@ -28,11 +29,23 @@ import (
2829
myschema "github.com/ajitpratap0/GoSQLX/pkg/schema/mysql"
2930
)
3031

32+
// isDockerAvailable checks whether the Docker daemon is reachable.
33+
// Returns false on macOS CI runners that have no Docker installed.
34+
func isDockerAvailable() bool {
35+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
36+
defer cancel()
37+
cmd := exec.CommandContext(ctx, "docker", "info")
38+
return cmd.Run() == nil
39+
}
40+
3141
func startMySQL(t *testing.T) *sql.DB {
3242
t.Helper()
3343
if testing.Short() {
3444
t.Skip("skipping testcontainers test in -short mode")
3545
}
46+
if !isDockerAvailable() {
47+
t.Skip("Docker not available, skipping integration test")
48+
}
3649
ctx := context.Background()
3750
req := testcontainers.ContainerRequest{
3851
Image: "mysql:8.0",

pkg/schema/postgres/loader_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"context"
1919
"database/sql"
2020
"fmt"
21+
"os/exec"
2122
"testing"
2223
"time"
2324

@@ -28,11 +29,23 @@ import (
2829
pgschema "github.com/ajitpratap0/GoSQLX/pkg/schema/postgres"
2930
)
3031

32+
// isDockerAvailable checks whether the Docker daemon is reachable.
33+
// Returns false on macOS CI runners that have no Docker installed.
34+
func isDockerAvailable() bool {
35+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
36+
defer cancel()
37+
cmd := exec.CommandContext(ctx, "docker", "info")
38+
return cmd.Run() == nil
39+
}
40+
3141
func startPostgres(t *testing.T) *sql.DB {
3242
t.Helper()
3343
if testing.Short() {
3444
t.Skip("skipping testcontainers test in -short mode")
3545
}
46+
if !isDockerAvailable() {
47+
t.Skip("Docker not available, skipping integration test")
48+
}
3649
ctx := context.Background()
3750
req := testcontainers.ContainerRequest{
3851
Image: "postgres:16-alpine",

0 commit comments

Comments
 (0)