TestcontainerEx.Container.Info (testcontainer_ex v0.7.1)

Copy Markdown View Source

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

amqp_url(container)

Returns an AMQP connection URL for RabbitMQ.

Uses :RABBITMQ_DEFAULT_USER, :RABBITMQ_DEFAULT_PASS, and :RABBITMQ_DEFAULT_VHOST from the container environment.

host(container)

Returns the host address for the container.

mongo_url(container)

Returns a MongoDB connection URL.

Uses :MONGO_INITDB_ROOT_USERNAME, :MONGO_INITDB_ROOT_PASSWORD, and :MONGO_INITDB_DATABASE from the container environment.

mysql_connect_opts(container, overrides \\ [])

@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.

pg_connect_opts(container, overrides \\ [])

@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.

port(container, container_port)

@spec port(TestcontainerEx.Container.Config.t(), integer()) :: integer() | nil

Returns the mapped host port for the given container port.

redis_url(container)

Returns a Redis connection URL.

If :REDIS_PASSWORD is set in the container environment, it is included in the URL.

url(container, container_port, scheme)

Returns a generic connection URL for the container.

Parameters

  • container — a started container config
  • container_port — the internal container port
  • scheme — 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"