diff --git a/postgres/lib/testcontainers/postgres.rb b/postgres/lib/testcontainers/postgres.rb index 57a1bfa..3f5dd19 100644 --- a/postgres/lib/testcontainers/postgres.rb +++ b/postgres/lib/testcontainers/postgres.rb @@ -36,7 +36,7 @@ def initialize(image = POSTGRES_DEFAULT_IMAGE, username: nil, password: nil, dat @password = password || ENV.fetch("POSTGRES_PASSWORD", POSTGRES_DEFAULT_PASSWORD) @database = database || ENV.fetch("POSTGRES_DATABASE", POSTGRES_DEFAULT_DATABASE) @healthcheck ||= add_healthcheck(_default_healthcheck_options) - @wait_for ||= add_wait_for(:healthcheck) + @wait_for = add_wait_for(:healthcheck) if !@wait_for || !kwargs[:wait_for] end # Starts the container diff --git a/postgres/test/postgres_container_test.rb b/postgres/test/postgres_container_test.rb index b75f412..092d724 100644 --- a/postgres/test/postgres_container_test.rb +++ b/postgres/test/postgres_container_test.rb @@ -80,4 +80,18 @@ def test_it_is_reachable client = PG.connect(host: @host, user: "test", password: "test", port: @port, dbname: "test") assert_equal({"number" => "1"}, client.exec("SELECT 1 AS number").first) end + + def test_it_uses_wait_for_healthcheck_by_default + expected_wait_for = Testcontainers::PostgresContainer.new(wait_for: :healthcheck).wait_for + actual_wait_for = Testcontainers::PostgresContainer.new.wait_for + + assert_equal expected_wait_for.source_location, actual_wait_for.source_location + end + + def test_it_uses_wait_for_healthcheck_by_default_when_port_bindings_are_specified + expected_wait_for = Testcontainers::PostgresContainer.new(wait_for: :healthcheck).wait_for + actual_wait_for = Testcontainers::PostgresContainer.new(port_bindings: {"5432": "15432"}).wait_for + + assert_equal expected_wait_for.source_location, actual_wait_for.source_location + end end