From e54e111f770e61ea6d321bb6c91ccf7d572d7ee4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maksymilian=20Chwa=C5=82ek?= Date: Tue, 7 Oct 2025 19:01:01 +0200 Subject: [PATCH 1/2] Fix default wait_for when port_bindings are specified --- postgres/lib/testcontainers/postgres.rb | 2 +- postgres/test/postgres_container_test.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) 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..a886484 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 From 2c8521cef4bcf791011a6f4b64e4e487642c7657 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maksymilian=20Chwa=C5=82ek?= Date: Tue, 7 Oct 2025 20:17:59 +0200 Subject: [PATCH 2/2] Fix style --- postgres/test/postgres_container_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/postgres/test/postgres_container_test.rb b/postgres/test/postgres_container_test.rb index a886484..092d724 100644 --- a/postgres/test/postgres_container_test.rb +++ b/postgres/test/postgres_container_test.rb @@ -90,7 +90,7 @@ def test_it_uses_wait_for_healthcheck_by_default 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 + 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