Skip to content

Commit

Permalink
chore: deprecated WithWaitStrategy from Postgres module, using core's
Browse files Browse the repository at this point in the history
  • Loading branch information
mdelapenya committed Mar 29, 2023
1 parent 96323f1 commit dbae345
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/modules/postgres.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ In the case you have a custom config file for Postgres, it's possible to copy th
#### Wait Strategies

Given you could need to wait for different conditions, in particular using a wait.ForSQL strategy,
the Postgres container exposes a `WithWaitStrategy` option to set a custom wait strategy.
the Postgres container exposes a `testcontainers.WithWaitStrategy` option to set a custom wait strategy.

<!--codeinclude-->
[Set Wait Strategy](../../modules/postgres/postgres_test.go) inside_block:withWaitStrategy
Expand Down
6 changes: 2 additions & 4 deletions modules/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"path/filepath"
"time"

"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
Expand Down Expand Up @@ -50,10 +49,9 @@ func (c *PostgresContainer) ConnectionString(ctx context.Context, args ...string
type PostgresContainerOption func(req *testcontainers.ContainerRequest)

// WithWaitStrategy sets the wait strategy for the postgres container
// Deprecated: use testcontainers.WithWaitStrategy instead
func WithWaitStrategy(strategies ...wait.Strategy) func(req *testcontainers.ContainerRequest) {
return func(req *testcontainers.ContainerRequest) {
req.WaitingFor = wait.ForAll(strategies...).WithDeadline(1 * time.Minute)
}
return testcontainers.WithWaitStrategy(strategies...)
}

// WithImage sets the image to be used for the postgres container
Expand Down
12 changes: 6 additions & 6 deletions modules/postgres/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestPostgres(t *testing.T) {
WithDatabase(dbname),
WithUsername(user),
WithPassword(password),
WithWaitStrategy(tt.wait),
testcontainers.WithWaitStrategy(tt.wait),
)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -110,7 +110,7 @@ func TestContainerWithWaitForSQL(t *testing.T) {
WithDatabase(dbname),
WithUsername(user),
WithPassword(password),
WithWaitStrategy(wait.ForSQL(nat.Port(port), "postgres", dbURL)),
testcontainers.WithWaitStrategy(wait.ForSQL(nat.Port(port), "postgres", dbURL)),
)
require.NoError(t, err)
require.NotNil(t, container)
Expand All @@ -123,7 +123,7 @@ func TestContainerWithWaitForSQL(t *testing.T) {
WithDatabase(dbname),
WithUsername(user),
WithPassword(password),
WithWaitStrategy(wait.ForSQL(nat.Port(port), "postgres", dbURL).WithStartupTimeout(time.Second*5).WithQuery("SELECT 10")),
testcontainers.WithWaitStrategy(wait.ForSQL(nat.Port(port), "postgres", dbURL).WithStartupTimeout(time.Second*5).WithQuery("SELECT 10")),
)
require.NoError(t, err)
require.NotNil(t, container)
Expand All @@ -135,7 +135,7 @@ func TestContainerWithWaitForSQL(t *testing.T) {
WithDatabase(dbname),
WithUsername(user),
WithPassword(password),
WithWaitStrategy(wait.ForSQL(nat.Port(port), "postgres", dbURL).WithStartupTimeout(time.Second*5).WithQuery("SELECT 'a' from b")),
testcontainers.WithWaitStrategy(wait.ForSQL(nat.Port(port), "postgres", dbURL).WithStartupTimeout(time.Second*5).WithQuery("SELECT 'a' from b")),
)
require.Error(t, err)
require.Nil(t, container)
Expand All @@ -151,7 +151,7 @@ func TestWithConfigFile(t *testing.T) {
WithDatabase(dbname),
WithUsername(user),
WithPassword(password),
WithWaitStrategy(wait.ForLog("database system is ready to accept connections").WithOccurrence(2).WithStartupTimeout(5*time.Second)),
testcontainers.WithWaitStrategy(wait.ForLog("database system is ready to accept connections").WithOccurrence(2).WithStartupTimeout(5*time.Second)),
)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -184,7 +184,7 @@ func TestWithInitScript(t *testing.T) {
WithDatabase(dbname),
WithUsername(user),
WithPassword(password),
WithWaitStrategy(wait.ForLog("database system is ready to accept connections").WithOccurrence(2).WithStartupTimeout(5*time.Second)),
testcontainers.WithWaitStrategy(wait.ForLog("database system is ready to accept connections").WithOccurrence(2).WithStartupTimeout(5*time.Second)),
)
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit dbae345

Please sign in to comment.