mirror of
https://github.com/gofiber/storage.git
synced 2025-10-23 16:33:15 +08:00
chore: implement more robust wait strategies in testcontainers services
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
|
||||
"github.com/testcontainers/testcontainers-go"
|
||||
"github.com/testcontainers/testcontainers-go/modules/clickhouse"
|
||||
"github.com/testcontainers/testcontainers-go/wait"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -39,6 +40,14 @@ func getTestConnection(t testing.TB, cfg Config) (*Storage, error) {
|
||||
clickhouse.WithUsername(clickhouseUser),
|
||||
clickhouse.WithPassword(clickhousePass),
|
||||
clickhouse.WithDatabase(clickhouseDB),
|
||||
testcontainers.WithWaitStrategy(
|
||||
wait.ForAll(
|
||||
wait.ForListeningPort("8123/tcp"),
|
||||
wait.NewHTTPStrategy("/").WithPort("8123/tcp").WithStatusCodeMatcher(func(status int) bool {
|
||||
return status == 200
|
||||
}),
|
||||
),
|
||||
),
|
||||
)
|
||||
testcontainers.CleanupContainer(t, c)
|
||||
if err != nil {
|
||||
|
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/testcontainers/testcontainers-go"
|
||||
"github.com/testcontainers/testcontainers-go/modules/minio"
|
||||
"github.com/testcontainers/testcontainers-go/wait"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -34,6 +35,10 @@ func newTestStore(t testing.TB) (*Storage, error) {
|
||||
img,
|
||||
minio.WithUsername(minioUser),
|
||||
minio.WithPassword(minioPass),
|
||||
testcontainers.WithWaitStrategy(
|
||||
wait.ForListeningPort("9000/tcp"),
|
||||
wait.ForHTTP("/minio/health/live").WithPort("9000"),
|
||||
),
|
||||
)
|
||||
testcontainers.CleanupContainer(t, c)
|
||||
if err != nil {
|
||||
|
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/testcontainers/testcontainers-go"
|
||||
"github.com/testcontainers/testcontainers-go/modules/mongodb"
|
||||
"github.com/testcontainers/testcontainers-go/wait"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -29,7 +30,15 @@ func newTestStore(t testing.TB) (*Storage, error) {
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
c, err := mongodb.Run(ctx, img, mongodb.WithUsername(mongoDBUser), mongodb.WithPassword(mongoDBPass))
|
||||
c, err := mongodb.Run(
|
||||
ctx, img, mongodb.WithUsername(mongoDBUser), mongodb.WithPassword(mongoDBPass),
|
||||
testcontainers.WithWaitStrategy(
|
||||
wait.ForAll(
|
||||
wait.ForListeningPort("27017/tcp"),
|
||||
wait.ForLog("Waiting for connections"),
|
||||
),
|
||||
),
|
||||
)
|
||||
testcontainers.CleanupContainer(t, c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/testcontainers/testcontainers-go"
|
||||
"github.com/testcontainers/testcontainers-go/modules/mysql"
|
||||
"github.com/testcontainers/testcontainers-go/wait"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -51,6 +52,10 @@ func mustStartMySQL(t testing.TB) *mysql.MySQLContainer {
|
||||
mysql.WithPassword(mysqlPass),
|
||||
mysql.WithUsername(mysqlUser),
|
||||
mysql.WithDatabase(mysqlDatabase),
|
||||
testcontainers.WithWaitStrategy(
|
||||
wait.ForListeningPort("3306/tcp"),
|
||||
wait.ForLog("port: 3306 MySQL Community Server"),
|
||||
),
|
||||
)
|
||||
testcontainers.CleanupContainer(t, c)
|
||||
require.NoError(t, err)
|
||||
|
@@ -8,7 +8,9 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/testcontainers/testcontainers-go"
|
||||
"github.com/testcontainers/testcontainers-go/modules/neo4j"
|
||||
"github.com/testcontainers/testcontainers-go/wait"
|
||||
)
|
||||
|
||||
var testStore *Storage
|
||||
@@ -21,6 +23,13 @@ func TestMain(m *testing.M) {
|
||||
neo4jContainer, err := neo4j.Run(ctx,
|
||||
"neo4j:5.26",
|
||||
neo4j.WithAdminPassword("pass#w*#d"),
|
||||
testcontainers.WithWaitStrategy(
|
||||
wait.ForAll(
|
||||
wait.ForListeningPort("7474/tcp"),
|
||||
wait.ForListeningPort("7687/tcp"),
|
||||
wait.ForLog("Bolt enabled on"),
|
||||
),
|
||||
),
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to start Neo4j container: %v", err)
|
||||
|
@@ -10,7 +10,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/testcontainers/testcontainers-go"
|
||||
"github.com/testcontainers/testcontainers-go/modules/postgres"
|
||||
"github.com/testcontainers/testcontainers-go/wait"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -36,11 +35,7 @@ func newTestStore(t testing.TB) (*Storage, error) {
|
||||
postgres.WithUsername(postgresUser),
|
||||
postgres.WithPassword(postgresPass),
|
||||
postgres.WithDatabase(postgresDatabase),
|
||||
testcontainers.WithWaitStrategy(
|
||||
// First, we wait for the container to log readiness twice.
|
||||
// This is because it will restart itself after the first startup.
|
||||
wait.ForLog("database system is ready to accept connections").WithOccurrence(2),
|
||||
),
|
||||
postgres.BasicWaitStrategies(),
|
||||
)
|
||||
testcontainers.CleanupContainer(t, c)
|
||||
require.NoError(t, err)
|
||||
|
@@ -6,7 +6,9 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/testcontainers/testcontainers-go"
|
||||
"github.com/testcontainers/testcontainers-go/modules/minio"
|
||||
"github.com/testcontainers/testcontainers-go/wait"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -35,6 +37,10 @@ func TestMain(m *testing.M) {
|
||||
img,
|
||||
minio.WithUsername(minioUser),
|
||||
minio.WithPassword(minioPass),
|
||||
testcontainers.WithWaitStrategy(
|
||||
wait.ForListeningPort("9000/tcp"),
|
||||
wait.ForHTTP("/minio/health/live").WithPort("9000"),
|
||||
),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
Reference in New Issue
Block a user