testcontainers-cpp 0.2.0
Native C++20 Testcontainers over the Docker Engine API
Loading...
Searching...
No Matches
testcontainers::modules::ClickHouseContainer Class Reference

A running ClickHouse server: endpoint getters plus the owned container. More...

#include <testcontainers/modules/ClickHouse.hpp>

Public Member Functions

const std::string & host () const noexcept
 The address a client in the test process connects to.
std::uint16_t http_port () const noexcept
 The host port published for the HTTP port 8123.
std::uint16_t native_port () const noexcept
 The host port published for the native-protocol port 9000 — what clickhouse-cpp's ClientOptions and clickhouse-client --port take.
const std::string & username () const noexcept
const std::string & password () const noexcept
const std::string & database () const noexcept
std::string connection_string () const
 Native-protocol DSN, clickhouse://user:password@host:native_port/database (percent-encoded) — e.g.
std::string http_url () const
 The HTTP base URL, e.g.
ExecResult exec_sql (const std::string &sql) const
 Run one SQL statement through the in-container clickhouse-client (native protocol over the container's loopback, the provisioned user, database()) — a zero-dependency seed/assert helper.
Containercontainer () noexcept
 The underlying container handle: exec clickhouse-client, read logs, copy files, stop() early, keep() it past the test.
const Containercontainer () const noexcept

Friends

class ClickHouseImage

Detailed Description

A running ClickHouse server: endpoint getters plus the owned container.

Move-only — it owns the core Container, whose destructor force-removes the server (RAII teardown; container().keep() or reuse opt out, see Container).

Member Function Documentation

◆ host()

const std::string & testcontainers::modules::ClickHouseContainer::host ( ) const
inlinenoexcept

The address a client in the test process connects to.

Resolved once, when the container started.

◆ http_port()

std::uint16_t testcontainers::modules::ClickHouseContainer::http_port ( ) const
inlinenoexcept

The host port published for the HTTP port 8123.

Resolved once, when the container started; a container restarted by hand gets fresh ephemeral ports — re-resolve via container() then.

◆ native_port()

std::uint16_t testcontainers::modules::ClickHouseContainer::native_port ( ) const
inlinenoexcept

The host port published for the native-protocol port 9000 — what clickhouse-cpp's ClientOptions and clickhouse-client --port take.

◆ username()

const std::string & testcontainers::modules::ClickHouseContainer::username ( ) const
inlinenoexcept

◆ password()

const std::string & testcontainers::modules::ClickHouseContainer::password ( ) const
inlinenoexcept

◆ database()

const std::string & testcontainers::modules::ClickHouseContainer::database ( ) const
inlinenoexcept

◆ connection_string()

std::string testcontainers::modules::ClickHouseContainer::connection_string ( ) const

Native-protocol DSN, clickhouse://user:password@host:native_port/database (percent-encoded) — e.g.

clickhouse://test:test@localhost:32768/test. clickhouse-cpp takes the discrete pieces instead: host(), native_port(), username(), password(), database(). HTTP consumers use http_url() — swapping this DSN's scheme would keep the wrong port.

◆ http_url()

std::string testcontainers::modules::ClickHouseContainer::http_url ( ) const

The HTTP base URL, e.g.

http://localhost:32769. Credentials go per request (basic auth, or the X-ClickHouse-User / X-ClickHouse-Key headers); JDBC-style URLs build on the same endpoint.

◆ exec_sql()

ExecResult testcontainers::modules::ClickHouseContainer::exec_sql ( const std::string & sql) const

Run one SQL statement through the in-container clickhouse-client (native protocol over the container's loopback, the provisioned user, database()) — a zero-dependency seed/assert helper.

Output is TabSeparated: one row per line, columns tab-separated, no headers. A failing statement is reported via the result's exit_code/stderr_data, not thrown.

◆ container() [1/2]

Container & testcontainers::modules::ClickHouseContainer::container ( )
inlinenoexcept

The underlying container handle: exec clickhouse-client, read logs, copy files, stop() early, keep() it past the test.

◆ container() [2/2]

const Container & testcontainers::modules::ClickHouseContainer::container ( ) const
inlinenoexcept

◆ ClickHouseImage

friend class ClickHouseImage
friend