Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion postgres/lib/testcontainers/postgres.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering whether I should get the param from kwargs or just specify it in the constructor

end

# Starts the container
Expand Down
14 changes: 14 additions & 0 deletions postgres/test/postgres_container_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading