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

A running NATS server: connection getters plus the owned container. More...

#include <testcontainers/modules/NATS.hpp>

Public Member Functions

const std::string & host () const noexcept
 The address a client in the test process connects to.
std::uint16_t port () const noexcept
 The host port published for the client port 4222.
std::uint16_t monitoring_port () const noexcept
 The host port published for the HTTP monitoring port 8222.
const std::string & username () const noexcept
 The username the server requires; empty when auth is off.
const std::string & password () const noexcept
 The password the server requires; empty when auth is off.
std::string url () const
 The server URL, nats://[user:password@]host:port — e.g.
std::string monitoring_url () const
 The monitoring base URL, e.g.
Containercontainer () noexcept
 The underlying container handle: read logs, stop() early, keep() it past the test.
const Containercontainer () const noexcept

Friends

class NATSImage

Detailed Description

A running NATS server: connection 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::NATSContainer::host ( ) const
inlinenoexcept

The address a client in the test process connects to.

Resolved once, when the container started.

◆ port()

std::uint16_t testcontainers::modules::NATSContainer::port ( ) const
inlinenoexcept

The host port published for the client port 4222.

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

◆ monitoring_port()

std::uint16_t testcontainers::modules::NATSContainer::monitoring_port ( ) const
inlinenoexcept

The host port published for the HTTP monitoring port 8222.

◆ username()

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

The username the server requires; empty when auth is off.

◆ password()

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

The password the server requires; empty when auth is off.

◆ url()

std::string testcontainers::modules::NATSContainer::url ( ) const

The server URL, nats://[user:password@]host:port — e.g.

nats://localhost:32771, or with credentials nats://app:s3cr3t@localhost:32771 (percent-encoded). Most clients accept credentials in the URL; clients that take them separately use host() / port() / username() / password() instead.

◆ monitoring_url()

std::string testcontainers::modules::NATSContainer::monitoring_url ( ) const

The monitoring base URL, e.g.

http://localhost:32772. The endpoints (/healthz, /varz, /connz, /jsz, ...) answer plain unauthenticated HTTP GETs — server introspection without a NATS client library.

◆ container() [1/2]

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

The underlying container handle: read logs, stop() early, keep() it past the test.

The default image has no shell or tools — exec has nothing to run (see NATSImage::kDefaultImage).

◆ container() [2/2]

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

◆ NATSImage

friend class NATSImage
friend