diff --git a/go.mod b/go.mod index 4c50eb6..349c5dd 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,6 @@ require ( github.com/gin-gonic/gin v1.12.0 github.com/jackc/pgx/v5 v5.11.0 github.com/joho/godotenv v1.5.1 - github.com/testcontainers/testcontainers-go v0.44.0 github.com/testcontainers/testcontainers-go/modules/postgres v0.44.0 go.opentelemetry.io/otel v1.46.0 go.opentelemetry.io/otel/metric v1.46.0 @@ -93,6 +92,7 @@ require ( github.com/shirou/gopsutil/v4 v4.26.6 // indirect github.com/sirupsen/logrus v1.9.4 // indirect github.com/stretchr/testify v1.12.1 // indirect + github.com/testcontainers/testcontainers-go v0.44.0 // indirect github.com/tklauser/go-sysconf v0.4.0 // indirect github.com/tklauser/numcpus v0.12.0 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect diff --git a/internal/core/repository/psql/user_repository_integration_test.go b/internal/core/repository/psql/user_repository_integration_test.go index 3c9a9c9..03bb098 100644 --- a/internal/core/repository/psql/user_repository_integration_test.go +++ b/internal/core/repository/psql/user_repository_integration_test.go @@ -18,27 +18,24 @@ import ( "sort" "strings" "testing" - "time" "github.com/duynhlab/user-service/internal/core/domain" "github.com/jackc/pgx/v5" "github.com/jackc/pgx/v5/pgxpool" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/postgres" - "github.com/testcontainers/testcontainers-go/wait" ) func newTestDB(t *testing.T) *pgxpool.Pool { t.Helper() ctx := context.Background() - container, err := postgres.Run(ctx, "postgres:16-alpine", + container, err := postgres.Run(ctx, "postgres:18-alpine", postgres.WithDatabase("user"), postgres.WithUsername("user"), postgres.WithPassword("secret"), - testcontainers.WithWaitStrategy( - wait.ForListeningPort("5432/tcp").WithStartupTimeout(90*time.Second), - ), + // Ready twice (initdb restarts the server once), then the published + // port: the module's own strategy, so a test never races the restart. + postgres.BasicWaitStrategies(), ) if err != nil { t.Fatalf("start postgres container: %v", err)