fix: wait only for port for sql server

This commit is contained in:
Peter 2022-08-06 18:48:17 +02:00
parent b407ad3755
commit 2134fae875
Signed by: prskr
GPG key ID: C1DB5D2E8DB512F9

View file

@ -2,11 +2,9 @@ package sql_test
import ( import (
"context" "context"
"fmt"
"testing" "testing"
"time" "time"
"github.com/docker/go-connections/nat"
"github.com/maxatome/go-testdeep/td" "github.com/maxatome/go-testdeep/td"
"github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait" "github.com/testcontainers/testcontainers-go/wait"
@ -40,9 +38,12 @@ func PreparePostgresContainer(tb testing.TB) (name string, cfg *config.Server) {
"POSTGRES_PASSWORD": dbPassword, "POSTGRES_PASSWORD": dbPassword,
"POSTGRES_DB": dbName, "POSTGRES_DB": dbName,
}, },
WaitingFor: wait.ForSQL(postgresPort, "pgx", func(port nat.Port) string { WaitingFor: wait.ForAll(
wait.ForListeningPort(postgresPort),
/*wait.ForSQL(postgresPort, "pgx", func(port nat.Port) string {
return fmt.Sprintf("postgres://%s:%s@localhost:%d/%s", dbUser, dbPassword, port.Int(), dbName) return fmt.Sprintf("postgres://%s:%s@localhost:%d/%s", dbUser, dbPassword, port.Int(), dbName)
}), }),*/
),
}, },
Started: true, Started: true,
Logger: testcontainers.TestLogger(tb), Logger: testcontainers.TestLogger(tb),
@ -92,9 +93,12 @@ func PrepareMariaDBContainer(tb testing.TB) (name string, cfg *config.Server) {
"MARIADB_RANDOM_ROOT_PASSWORD": "1", "MARIADB_RANDOM_ROOT_PASSWORD": "1",
"MARIADB_DATABASE": dbName, "MARIADB_DATABASE": dbName,
}, },
WaitingFor: wait.ForSQL(mysqlPort, "mysql", func(port nat.Port) string { WaitingFor: wait.ForAll(
wait.ForListeningPort(mysqlPort),
/* wait.ForSQL(mysqlPort, "mysql", func(port nat.Port) string {
return fmt.Sprintf("%s:%s@tcp(localhost:%d)/%s", dbUser, dbPassword, port.Int(), dbName) return fmt.Sprintf("%s:%s@tcp(localhost:%d)/%s", dbUser, dbPassword, port.Int(), dbName)
}), }),*/
),
}, },
Started: true, Started: true,
Logger: testcontainers.TestLogger(tb), Logger: testcontainers.TestLogger(tb),