Skip to content

Commit 35eea06

Browse files
Ajit Pratap Singhclaude
authored andcommitted
fix(schema): stabilize testcontainers tests and allow docker GHSA
- Add testing.Short() guard to postgres/mysql loader tests so they skip in the Race Detector job (which runs with -short) - Replace wait.ForListeningPort with wait.ForLog for postgres container to wait until the database is fully ready (fixes EOF on create tables) - Add db.Ping retry loop after container start for both postgres and mysql to handle the window between port-listen and query-ready - Allow GHSA-x744-4wpc-v9h2 (docker AuthZ bypass) in dependency review; transitive dep via testcontainers-go with no upstream fix available Closes race-detector and macOS test failures on PR #471. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent fe24146 commit 35eea06

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

.github/workflows/security.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ jobs:
164164
uses: actions/dependency-review-action@v4
165165
with:
166166
fail-on-severity: high
167+
# GHSA-x744-4wpc-v9h2: docker/docker AuthZ plugin bypass with oversized
168+
# request bodies. Transitive dep via testcontainers-go (test-only).
169+
# No fixed version available upstream as of 2026-03-29.
170+
allow-ghsas: GHSA-x744-4wpc-v9h2
167171
# Include both the compound SPDX expression and individual components
168172
# to handle golang.org/x packages which report as compound license
169173
allow-licenses: >-

pkg/schema/mysql/loader_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"database/sql"
2020
"fmt"
2121
"testing"
22+
"time"
2223

2324
_ "github.com/go-sql-driver/mysql"
2425
"github.com/testcontainers/testcontainers-go"
@@ -29,6 +30,9 @@ import (
2930

3031
func startMySQL(t *testing.T) *sql.DB {
3132
t.Helper()
33+
if testing.Short() {
34+
t.Skip("skipping testcontainers test in -short mode")
35+
}
3236
ctx := context.Background()
3337
req := testcontainers.ContainerRequest{
3438
Image: "mysql:8.0",
@@ -57,6 +61,17 @@ func startMySQL(t *testing.T) *sql.DB {
5761
}
5862
t.Cleanup(func() { _ = db.Close() })
5963

64+
// Wait for MySQL to be fully ready to accept queries.
65+
for i := 0; i < 30; i++ {
66+
if err := db.PingContext(ctx); err == nil {
67+
break
68+
}
69+
time.Sleep(500 * time.Millisecond)
70+
}
71+
if err := db.PingContext(ctx); err != nil {
72+
t.Fatalf("ping db after retries: %v", err)
73+
}
74+
6075
_, err = db.Exec(`
6176
CREATE TABLE products (
6277
id INT AUTO_INCREMENT PRIMARY KEY,

pkg/schema/postgres/loader_test.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"database/sql"
2020
"fmt"
2121
"testing"
22+
"time"
2223

2324
_ "github.com/lib/pq"
2425
"github.com/testcontainers/testcontainers-go"
@@ -29,6 +30,9 @@ import (
2930

3031
func startPostgres(t *testing.T) *sql.DB {
3132
t.Helper()
33+
if testing.Short() {
34+
t.Skip("skipping testcontainers test in -short mode")
35+
}
3236
ctx := context.Background()
3337
req := testcontainers.ContainerRequest{
3438
Image: "postgres:16-alpine",
@@ -38,7 +42,7 @@ func startPostgres(t *testing.T) *sql.DB {
3842
"POSTGRES_PASSWORD": "test",
3943
"POSTGRES_DB": "testdb",
4044
},
41-
WaitingFor: wait.ForListeningPort("5432/tcp"),
45+
WaitingFor: wait.ForLog("database system is ready to accept connections").WithOccurrence(2),
4246
}
4347
c, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
4448
ContainerRequest: req,
@@ -58,6 +62,17 @@ func startPostgres(t *testing.T) *sql.DB {
5862
}
5963
t.Cleanup(func() { _ = db.Close() })
6064

65+
// Wait for the database to be fully ready to accept queries.
66+
for i := 0; i < 30; i++ {
67+
if err := db.PingContext(ctx); err == nil {
68+
break
69+
}
70+
time.Sleep(500 * time.Millisecond)
71+
}
72+
if err := db.PingContext(ctx); err != nil {
73+
t.Fatalf("ping db after retries: %v", err)
74+
}
75+
6176
_, err = db.Exec(`
6277
CREATE TABLE users (
6378
id SERIAL PRIMARY KEY,

0 commit comments

Comments
 (0)