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
M Dockerfile.test
+2, -2
1@@ -1,6 +1,6 @@
2-FROM golang:1.25.0-alpine
3+FROM golang:1.25.0-bookworm
4 
5-RUN apk add --no-cache rsync openssh make gcc musl-dev git
6+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/*
7 
8 WORKDIR /app
9 
M Makefile
+4, -0
 1@@ -28,6 +28,10 @@ test:
 2 	go test ./...
 3 .PHONY: test
 4 
 5+test-integration:
 6+	REQUIRE_TESTCONTAINERS=1 go test ./...
 7+.PHONY: test-integration
 8+
 9 snaps:
10 	UPDATE_SNAPS=true go test ./...
11 .PHONY: snaps
M pico.sh
+1, -1
1@@ -10,7 +10,7 @@ printf "\x1b[33m[%s] running ci (event=%s)\x1b[0m\n" "$JOB_ID" "$EVENT_TYPE"
2 zmx run lint -d  docker run -t --rm -v $(pwd):/app -w /app golangci/golangci-lint:v2.11.4 golangci-lint run
3 zmx run build -d docker build -t pico-test -f ./Dockerfile.test .
4 zmx wait "*"
5-zmx run test docker run -t --rm -v /var/run/docker.sock:/var/run/docker.sock pico-test
6+zmx run test docker run -t --rm -v /var/run/docker.sock:/var/run/docker.sock -e REQUIRE_TESTCONTAINERS=1 pico-test
7 
8 printf "\x1b[32msuccess tests!\x1b[0m\n"
9 
M pkg/db/postgres/storage_test.go
+13, -23
 1@@ -30,26 +30,6 @@ func setupContainerRuntime() bool {
 2 		return true
 3 	}
 4 
 5-	// Try podman first
 6-	if cmd := exec.Command("podman", "info"); cmd.Run() == nil {
 7-		// For podman, we need to ensure the socket is running
 8-		// User should run: systemctl --user start podman.socket
 9-		_ = os.Setenv("TESTCONTAINERS_RYUK_DISABLED", "true")
10-
11-		// Check if socket exists and is accessible
12-		xdgRuntime := os.Getenv("XDG_RUNTIME_DIR")
13-		if xdgRuntime != "" {
14-			socketPath := xdgRuntime + "/podman/podman.sock"
15-			if _, err := os.Stat(socketPath); err == nil {
16-				_ = os.Setenv("DOCKER_HOST", "unix://"+socketPath)
17-				return true
18-			}
19-		}
20-		// Socket not available, need to start it
21-		fmt.Println("Podman detected but socket not running. Run: systemctl --user start podman.socket")
22-		return false
23-	}
24-
25 	// Try docker
26 	if cmd := exec.Command("docker", "info"); cmd.Run() == nil {
27 		return true
28@@ -62,6 +42,9 @@ func TestMain(m *testing.M) {
29 	ctx := context.Background()
30 	testLogger = slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelError}))
31 
32+	// REQUIRE_TESTCONTAINERS=1 makes the build fail if containers can't start
33+	requireContainers := os.Getenv("REQUIRE_TESTCONTAINERS") == "1"
34+
35 	// Check for external database URL first (for CI/CD or manual testing)
36 	if dbURL := os.Getenv("TEST_DATABASE_URL"); dbURL != "" {
37 		testDB = NewDB(dbURL, testLogger)
38@@ -77,10 +60,13 @@ func TestMain(m *testing.M) {
39 		fmt.Println("Container runtime not available, skipping integration tests")
40 		fmt.Println("To run tests, either:")
41 		fmt.Println("  - Set TEST_DATABASE_URL to a postgres connection string")
42-		fmt.Println("  - Start podman socket: systemctl --user start podman.socket")
43 		fmt.Println("  - Start docker daemon")
44 		skipTests = true
45-		os.Exit(0)
46+		exitCode := 0
47+		if requireContainers {
48+			exitCode = 1
49+		}
50+		os.Exit(exitCode)
51 	}
52 
53 	pgContainer, err := postgres.Run(ctx,
54@@ -96,7 +82,11 @@ func TestMain(m *testing.M) {
55 	if err != nil {
56 		fmt.Printf("Failed to start postgres container (Docker may not be running): %s\n", err)
57 		skipTests = true
58-		os.Exit(0)
59+		exitCode := 0
60+		if requireContainers {
61+			exitCode = 1
62+		}
63+		os.Exit(exitCode)
64 	}
65 
66 	connStr, err := pgContainer.ConnectionString(ctx, "sslmode=disable")