Commit 8936652
Eric Bower
·
2026-05-16 12:39:06 -0400 EDT
parent 77b9fc0
fix: require testcontainers for pico.sh ci
4 files changed,
+20,
-26
+2,
-2
| ... | ... | @@ -1,6 +1,6 @@ | |
| 1 | - | FROM golang:1.25.0-alpine | |
| 1 | + | FROM golang:1.25.0-bookworm | |
| 2 | 2 | ||
| 3 | - | RUN apk add --no-cache rsync openssh make gcc musl-dev git | |
| 3 | + | RUN apt-get update && apt-get install -y --no-install-recommends rsync openssh-client make gcc git docker.io && rm -rf /var/lib/apt/lists/* | |
| 4 | 4 | ||
| 5 | 5 | WORKDIR /app | |
| 6 | 6 |
M
Makefile
+4,
-0
| ... | ... | @@ -28,6 +28,10 @@ test: | |
| 28 | 28 | go test ./... | |
| 29 | 29 | .PHONY: test | |
| 30 | 30 | ||
| 31 | + | test-integration: | |
| 32 | + | REQUIRE_TESTCONTAINERS=1 go test ./... | |
| 33 | + | .PHONY: test-integration | |
| 34 | + | ||
| 31 | 35 | snaps: | |
| 32 | 36 | UPDATE_SNAPS=true go test ./... | |
| 33 | 37 | .PHONY: snaps |
M
pico.sh
+1,
-1
| ... | ... | @@ -10,7 +10,7 @@ printf "\x1b[33m[%s] running ci (event=%s)\x1b[0m\n" "$JOB_ID" "$EVENT_TYPE" | |
| 10 | 10 | zmx run lint -d docker run -t --rm -v $(pwd):/app -w /app golangci/golangci-lint:v2.11.4 golangci-lint run | |
| 11 | 11 | zmx run build -d docker build -t pico-test -f ./Dockerfile.test . | |
| 12 | 12 | zmx wait "*" | |
| 13 | - | zmx run test docker run -t --rm -v /var/run/docker.sock:/var/run/docker.sock pico-test | |
| 13 | + | zmx run test docker run -t --rm -v /var/run/docker.sock:/var/run/docker.sock -e REQUIRE_TESTCONTAINERS=1 pico-test | |
| 14 | 14 | ||
| 15 | 15 | printf "\x1b[32msuccess tests!\x1b[0m\n" | |
| 16 | 16 |
+13,
-23
| ... | ... | @@ -30,26 +30,6 @@ func setupContainerRuntime() bool { | |
| 30 | 30 | return true | |
| 31 | 31 | } | |
| 32 | 32 | ||
| 33 | - | // Try podman first | |
| 34 | - | if cmd := exec.Command("podman", "info"); cmd.Run() == nil { | |
| 35 | - | // For podman, we need to ensure the socket is running | |
| 36 | - | // User should run: systemctl --user start podman.socket | |
| 37 | - | _ = os.Setenv("TESTCONTAINERS_RYUK_DISABLED", "true") | |
| 38 | - | ||
| 39 | - | // Check if socket exists and is accessible | |
| 40 | - | xdgRuntime := os.Getenv("XDG_RUNTIME_DIR") | |
| 41 | - | if xdgRuntime != "" { | |
| 42 | - | socketPath := xdgRuntime + "/podman/podman.sock" | |
| 43 | - | if _, err := os.Stat(socketPath); err == nil { | |
| 44 | - | _ = os.Setenv("DOCKER_HOST", "unix://"+socketPath) | |
| 45 | - | return true | |
| 46 | - | } | |
| 47 | - | } | |
| 48 | - | // Socket not available, need to start it | |
| 49 | - | fmt.Println("Podman detected but socket not running. Run: systemctl --user start podman.socket") | |
| 50 | - | return false | |
| 51 | - | } | |
| 52 | - | ||
| 53 | 33 | // Try docker | |
| 54 | 34 | if cmd := exec.Command("docker", "info"); cmd.Run() == nil { | |
| 55 | 35 | return true |
| ... | ... | @@ -62,6 +42,9 @@ func TestMain(m *testing.M) { | |
| 62 | 42 | ctx := context.Background() | |
| 63 | 43 | testLogger = slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelError})) | |
| 64 | 44 | ||
| 45 | + | // REQUIRE_TESTCONTAINERS=1 makes the build fail if containers can't start | |
| 46 | + | requireContainers := os.Getenv("REQUIRE_TESTCONTAINERS") == "1" | |
| 47 | + | ||
| 65 | 48 | // Check for external database URL first (for CI/CD or manual testing) | |
| 66 | 49 | if dbURL := os.Getenv("TEST_DATABASE_URL"); dbURL != "" { | |
| 67 | 50 | testDB = NewDB(dbURL, testLogger) |
| ... | ... | @@ -77,10 +60,13 @@ func TestMain(m *testing.M) { | |
| 77 | 60 | fmt.Println("Container runtime not available, skipping integration tests") | |
| 78 | 61 | fmt.Println("To run tests, either:") | |
| 79 | 62 | fmt.Println(" - Set TEST_DATABASE_URL to a postgres connection string") | |
| 80 | - | fmt.Println(" - Start podman socket: systemctl --user start podman.socket") | |
| 81 | 63 | fmt.Println(" - Start docker daemon") | |
| 82 | 64 | skipTests = true | |
| 83 | - | os.Exit(0) | |
| 65 | + | exitCode := 0 | |
| 66 | + | if requireContainers { | |
| 67 | + | exitCode = 1 | |
| 68 | + | } | |
| 69 | + | os.Exit(exitCode) | |
| 84 | 70 | } | |
| 85 | 71 | ||
| 86 | 72 | pgContainer, err := postgres.Run(ctx, |
| ... | ... | @@ -96,7 +82,11 @@ func TestMain(m *testing.M) { | |
| 96 | 82 | if err != nil { | |
| 97 | 83 | fmt.Printf("Failed to start postgres container (Docker may not be running): %s\n", err) | |
| 98 | 84 | skipTests = true | |
| 99 | - | os.Exit(0) | |
| 85 | + | exitCode := 0 | |
| 86 | + | if requireContainers { | |
| 87 | + | exitCode = 1 | |
| 88 | + | } | |
| 89 | + | os.Exit(exitCode) | |
| 100 | 90 | } | |
| 101 | 91 | ||
| 102 | 92 | connStr, err := pgContainer.ConnectionString(ctx, "sslmode=disable") |