From 863fbede4935eb5898ecf78441b7a4e879bc52a1 Mon Sep 17 00:00:00 2001 From: Vitaly Slobodin Date: Wed, 18 Nov 2026 20:40:24 +0100 Subject: [PATCH] Keep default ClickHouse ports when exposed_ports is given Passing `exposed_ports:` to `ClickhouseContainer.new` replaced the default 9000/8123 ports, because the hardcoded value was overridden by **kwargs. Without 8123 the HTTP wait strategy failed and `clickhouse_url` broke. Expose the default ports in `#start` via `with_exposed_ports`, matching `PostgresContainer`. This adds them to any user-supplied ports instead of replacing them. --- clickhouse/lib/testcontainers/clickhouse.rb | 3 ++- clickhouse/test/clickhouse_container_test.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/clickhouse/lib/testcontainers/clickhouse.rb b/clickhouse/lib/testcontainers/clickhouse.rb index 82f5db6..a715761 100644 --- a/clickhouse/lib/testcontainers/clickhouse.rb +++ b/clickhouse/lib/testcontainers/clickhouse.rb @@ -38,7 +38,7 @@ class ClickhouseContainer < ::Testcontainers::DockerContainer # @param kwargs [Hash] the options to pass to the container. See {DockerContainer#initialize} # @return [ClickhouseContainer] a new instance of ClickhouseContainer def initialize(image = CLICKHOUSE_DEFAULT_IMAGE, username: nil, password: nil, database: nil, **kwargs) - super(image, wait_for: WAIT_FOR_PROC, exposed_ports: [CLICKHOUSE_DEFAULT_PORT, CLICKHOUSE_DEFAULT_HTTP_PORT], **kwargs) + super(image, wait_for: WAIT_FOR_PROC, **kwargs) @username = username || ENV.fetch("CLICKHOUSE_USER", CLICKHOUSE_DEFAULT_USER) @password = password || ENV.fetch("CLICKHOUSE_PASSWORD", CLICKHOUSE_DEFAULT_PASS) @database = database || ENV.fetch("CLICKHOUSE_DB", CLICKHOUSE_DB) @@ -48,6 +48,7 @@ def initialize(image = CLICKHOUSE_DEFAULT_IMAGE, username: nil, password: nil, d # # @return [ClickhouseContainer] self def start + with_exposed_ports(port, http_port) _configure super end diff --git a/clickhouse/test/clickhouse_container_test.rb b/clickhouse/test/clickhouse_container_test.rb index 9d9f7b4..4983e89 100644 --- a/clickhouse/test/clickhouse_container_test.rb +++ b/clickhouse/test/clickhouse_container_test.rb @@ -50,6 +50,18 @@ def test_it_has_the_default_ports_mapped assert @container.mapped_port(9000) end + def test_it_keeps_default_ports_when_custom_exposed_ports_are_given + container = Testcontainers::ClickhouseContainer.new(exposed_ports: [8443]) + container.start + + assert container.mapped_port(8443) + assert container.mapped_port(container.port) + assert container.mapped_port(container.http_port) + ensure + container&.stop if container&.running? + container&.remove if container&.exists? + end + def test_it_returns_the_default_clickhouse_url assert_equal "clickhouse://default:password@#{@host}:#{@port}/default", @container.clickhouse_url end