Convenience functions for extracting runtime information from a started container.
While Config holds the full configuration, Info provides focused accessors
for the most commonly needed runtime details — host, port, connection strings.
Usage
{:ok, container} = TestcontainerEx.start_container(PostgresContainer.new())
# Get connection parameters for Postgrex
opts = TestcontainerEx.Container.Info.pg_connect_opts(container)
# Get a generic connection URL
url = TestcontainerEx.Container.Info.url(container, 5432, "postgres")
Summary
Functions
Returns an AMQP connection URL for RabbitMQ.
Returns the host address for the container.
Returns a MongoDB connection URL.
Returns connection options suitable for MyXQL.start_link/1.
Returns connection options suitable for Postgrex.start_link/1.
Returns the mapped host port for the given container port.
Returns a Redis connection URL.
Returns a generic connection URL for the container.
Functions
@spec amqp_url(TestcontainerEx.Container.Config.t()) :: String.t()
Returns an AMQP connection URL for RabbitMQ.
Uses :RABBITMQ_DEFAULT_USER, :RABBITMQ_DEFAULT_PASS,
and :RABBITMQ_DEFAULT_VHOST from the container environment.
@spec host(TestcontainerEx.Container.Config.t()) :: String.t()
Returns the host address for the container.
@spec mongo_url(TestcontainerEx.Container.Config.t()) :: String.t()
Returns a MongoDB connection URL.
Uses :MONGO_INITDB_ROOT_USERNAME, :MONGO_INITDB_ROOT_PASSWORD,
and :MONGO_INITDB_DATABASE from the container environment.
@spec mysql_connect_opts( TestcontainerEx.Container.Config.t(), keyword() ) :: keyword()
Returns connection options suitable for MyXQL.start_link/1.
Requires the container to have :MYSQL_USER, :MYSQL_PASSWORD,
and :MYSQL_DATABASE environment variables set.
@spec pg_connect_opts( TestcontainerEx.Container.Config.t(), keyword() ) :: keyword()
Returns connection options suitable for Postgrex.start_link/1.
Requires the container to have :POSTGRES_USER, :POSTGRES_PASSWORD,
and :POSTGRES_DB environment variables set.
@spec port(TestcontainerEx.Container.Config.t(), integer()) :: integer() | nil
Returns the mapped host port for the given container port.
@spec redis_url(TestcontainerEx.Container.Config.t()) :: String.t()
Returns a Redis connection URL.
If :REDIS_PASSWORD is set in the container environment, it is included
in the URL.
@spec url(TestcontainerEx.Container.Config.t(), integer(), String.t()) :: String.t()
Returns a generic connection URL for the container.
Parameters
container— a started container configcontainer_port— the internal container portscheme— protocol scheme (e.g. "postgres", "redis", "http")
Examples
iex> Info.url(container, 5432, "postgres")
"postgres://localhost:55123"
iex> Info.url(container, 6379, "redis")
"redis://localhost:55124"