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
22
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/*
44
55 WORKDIR /app
66
+4, -0
......@@ -28,6 +28,10 @@ test:
2828 go test ./...
2929 .PHONY: test
3030
31+test-integration:
32+ REQUIRE_TESTCONTAINERS=1 go test ./...
33+.PHONY: test-integration
34+
3135 snaps:
3236 UPDATE_SNAPS=true go test ./...
3337 .PHONY: snaps
+1, -1
......@@ -10,7 +10,7 @@ printf "\x1b[33m[%s] running ci (event=%s)\x1b[0m\n" "$JOB_ID" "$EVENT_TYPE"
1010 zmx run lint -d docker run -t --rm -v $(pwd):/app -w /app golangci/golangci-lint:v2.11.4 golangci-lint run
1111 zmx run build -d docker build -t pico-test -f ./Dockerfile.test .
1212 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
1414
1515 printf "\x1b[32msuccess tests!\x1b[0m\n"
1616
+13, -23
......@@ -30,26 +30,6 @@ func setupContainerRuntime() bool {
3030 return true
3131 }
3232
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-
5333 // Try docker
5434 if cmd := exec.Command("docker", "info"); cmd.Run() == nil {
5535 return true
......@@ -62,6 +42,9 @@ func TestMain(m *testing.M) {
6242 ctx := context.Background()
6343 testLogger = slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelError}))
6444
45+ // REQUIRE_TESTCONTAINERS=1 makes the build fail if containers can't start
46+ requireContainers := os.Getenv("REQUIRE_TESTCONTAINERS") == "1"
47+
6548 // Check for external database URL first (for CI/CD or manual testing)
6649 if dbURL := os.Getenv("TEST_DATABASE_URL"); dbURL != "" {
6750 testDB = NewDB(dbURL, testLogger)
......@@ -77,10 +60,13 @@ func TestMain(m *testing.M) {
7760 fmt.Println("Container runtime not available, skipping integration tests")
7861 fmt.Println("To run tests, either:")
7962 fmt.Println(" - Set TEST_DATABASE_URL to a postgres connection string")
80- fmt.Println(" - Start podman socket: systemctl --user start podman.socket")
8163 fmt.Println(" - Start docker daemon")
8264 skipTests = true
83- os.Exit(0)
65+ exitCode := 0
66+ if requireContainers {
67+ exitCode = 1
68+ }
69+ os.Exit(exitCode)
8470 }
8571
8672 pgContainer, err := postgres.Run(ctx,
......@@ -96,7 +82,11 @@ func TestMain(m *testing.M) {
9682 if err != nil {
9783 fmt.Printf("Failed to start postgres container (Docker may not be running): %s\n", err)
9884 skipTests = true
99- os.Exit(0)
85+ exitCode := 0
86+ if requireContainers {
87+ exitCode = 1
88+ }
89+ os.Exit(exitCode)
10090 }
10191
10292 connStr, err := pgContainer.ConnectionString(ctx, "sslmode=disable")