Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/container/cassandra_container.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ defmodule Testcontainers.CassandraContainer do
@doc """
Retrieves the port mapped by the Docker host for the Cassandra container.
"""
def port(%Container{} = container), do: Container.mapped_port(container, @default_port)
def port(%Container{} = container), do: Testcontainers.get_port(container, @default_port)

@doc """
Generates the connection URL for accessing the Cassandra service running within the container.
"""
def connection_uri(%Container{} = container) do
"#{Testcontainers.get_host()}:#{port(container)}"
"#{Testcontainers.get_host(container)}:#{port(container)}"
end

defimpl ContainerBuilder do
Expand Down
6 changes: 3 additions & 3 deletions lib/container/ceph_container.ex
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ defmodule Testcontainers.CephContainer do
iex> CephContainer.port(container)
32768 # This value will be different depending on the mapped port.
"""
def port(%Container{} = container), do: Container.mapped_port(container, @default_port)
def port(%Container{} = container), do: Testcontainers.get_port(container, @default_port)

@doc """
Generates the connection URL for accessing the Ceph service running within the container.
Expand All @@ -192,7 +192,7 @@ defmodule Testcontainers.CephContainer do
"http://localhost:32768" # This value will be different depending on the mapped port.
"""
def connection_url(%Container{} = container) do
"http://#{Testcontainers.get_host()}:#{port(container)}"
"http://#{Testcontainers.get_host(container)}:#{port(container)}"
end

@doc """
Expand All @@ -203,7 +203,7 @@ defmodule Testcontainers.CephContainer do
[
port: CephContainer.port(container),
scheme: "http://",
host: Testcontainers.get_host(),
host: Testcontainers.get_host(container),
access_key_id: container.environment[:CEPH_DEMO_ACCESS_KEY],
secret_access_key: container.environment[:CEPH_DEMO_SECRET_KEY]
]
Expand Down
2 changes: 1 addition & 1 deletion lib/container/emqx_container.ex
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ defmodule Testcontainers.EmqxContainer do
Returns the port on the _host machine_ where the Emqx container is listening.
"""
def mqtt_port(%Container{} = container),
do: Container.mapped_port(container, @default_mqtt_port)
do: Testcontainers.get_port(container, @default_mqtt_port)

defimpl ContainerBuilder do
import Container
Expand Down
6 changes: 3 additions & 3 deletions lib/container/kafka_container.ex
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,15 @@ defmodule Testcontainers.KafkaContainer do
Returns the bootstrap servers string for connecting to the Kafka container.
"""
def bootstrap_servers(%Container{} = container) do
port = Container.mapped_port(container, @default_internal_kafka_port)
"#{Testcontainers.get_host()}:#{port}"
port = Testcontainers.get_port(container, @default_internal_kafka_port)
"#{Testcontainers.get_host(container)}:#{port}"
end

@doc """
Returns the port on the host machine where the Kafka container is listening.
"""
def port(%Container{} = container),
do: Container.mapped_port(container, @default_internal_kafka_port)
do: Testcontainers.get_port(container, @default_internal_kafka_port)

defimpl Testcontainers.ContainerBuilder do
import Container
Expand Down
6 changes: 3 additions & 3 deletions lib/container/minio_container.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ defmodule Testcontainers.MinioContainer do
@doc """
Retrieves the port mapped by the Docker host for the Minio container.
"""
def port(%Container{} = container), do: Container.mapped_port(container, @default_s3_port)
def port(%Container{} = container), do: Testcontainers.get_port(container, @default_s3_port)

@doc """
Generates the connection URL for accessing the Minio service running within the container.
"""
def connection_url(%Container{} = container) do
"http://#{Testcontainers.get_host()}:#{port(container)}"
"http://#{Testcontainers.get_host(container)}:#{port(container)}"
end

@doc """
Expand All @@ -66,7 +66,7 @@ defmodule Testcontainers.MinioContainer do
[
port: MinioContainer.port(container),
scheme: "http://",
host: Testcontainers.get_host(),
host: Testcontainers.get_host(container),
access_key_id: container.environment[:MINIO_ROOT_USER],
secret_access_key: container.environment[:MINIO_ROOT_PASSWORD]
]
Expand Down
4 changes: 2 additions & 2 deletions lib/container/mysql_container.ex
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,14 @@ defmodule Testcontainers.MySqlContainer do
@doc """
Returns the port on the _host machine_ where the MySql container is listening.
"""
def port(%Container{} = container), do: Container.mapped_port(container, @default_port)
def port(%Container{} = container), do: Testcontainers.get_port(container, @default_port)

@doc """
Returns the connection parameters to connect to the database from the _host machine_.
"""
def connection_parameters(%Container{} = container) do
[
hostname: Testcontainers.get_host(),
hostname: Testcontainers.get_host(container),
port: port(container),
username: container.environment[:MYSQL_USER],
password: container.environment[:MYSQL_PASSWORD],
Expand Down
4 changes: 2 additions & 2 deletions lib/container/postgres_container.ex
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,14 @@ defmodule Testcontainers.PostgresContainer do
@doc """
Returns the port on the _host machine_ where the Postgres container is listening.
"""
def port(%Container{} = container), do: Container.mapped_port(container, @default_port)
def port(%Container{} = container), do: Testcontainers.get_port(container, @default_port)

@doc """
Returns the connection parameters to connect to the database from the _host machine_.
"""
def connection_parameters(%Container{} = container) do
[
hostname: Testcontainers.get_host(),
hostname: Testcontainers.get_host(container),
port: port(container),
username: container.environment[:POSTGRES_USER],
password: container.environment[:POSTGRES_PASSWORD],
Expand Down
6 changes: 3 additions & 3 deletions lib/container/rabbitmq_container.ex
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ defmodule Testcontainers.RabbitMQContainer do
"""
def port(%Container{} = container),
do:
Container.mapped_port(
Testcontainers.get_port(
container,
String.to_integer(container.environment[:RABBITMQ_NODE_PORT])
)
Expand All @@ -210,7 +210,7 @@ defmodule Testcontainers.RabbitMQContainer do
"amqp://guest:guest@localhost:32768/vhost"
"""
def connection_url(%Container{} = container) do
"amqp://#{container.environment[:RABBITMQ_DEFAULT_USER]}:#{container.environment[:RABBITMQ_DEFAULT_PASS]}@#{Testcontainers.get_host()}:#{port(container)}#{virtual_host_segment(container)}"
"amqp://#{container.environment[:RABBITMQ_DEFAULT_USER]}:#{container.environment[:RABBITMQ_DEFAULT_PASS]}@#{Testcontainers.get_host(container)}:#{port(container)}#{virtual_host_segment(container)}"
end

@doc """
Expand All @@ -233,7 +233,7 @@ defmodule Testcontainers.RabbitMQContainer do
"""
def connection_parameters(%Container{} = container) do
[
host: Testcontainers.get_host(),
host: Testcontainers.get_host(container),
port: port(container),
username: container.environment[:RABBITMQ_DEFAULT_USER],
password: container.environment[:RABBITMQ_DEFAULT_PASS],
Expand Down
4 changes: 2 additions & 2 deletions lib/container/redis_container.ex
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ defmodule Testcontainers.RedisContainer do
@doc """
Returns the port on the _host machine_ where the Redis container is listening.
"""
def port(%Container{} = container), do: Container.mapped_port(container, @default_port)
def port(%Container{} = container), do: Testcontainers.get_port(container, @default_port)

@doc """
Generates the connection URL for accessing the Redis service running within the container.
Expand All @@ -141,7 +141,7 @@ defmodule Testcontainers.RedisContainer do
def connection_url(%Container{} = container) do
password = container.environment[:REDIS_PASSWORD]
auth_part = if password, do: ":#{password}@", else: ""
"redis://#{auth_part}#{Testcontainers.get_host()}:#{port(container)}/"
"redis://#{auth_part}#{Testcontainers.get_host(container)}:#{port(container)}/"
end

defimpl ContainerBuilder do
Expand Down
16 changes: 8 additions & 8 deletions lib/container/toxiproxy_container.ex
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ defmodule Testcontainers.ToxiproxyContainer do
Returns the mapped control port on the host for the running container.
"""
def mapped_control_port(%Container{} = container) do
Container.mapped_port(container, @control_port)
Testcontainers.get_port(container, @control_port)
end

@doc """
Expand All @@ -92,7 +92,7 @@ defmodule Testcontainers.ToxiproxyContainer do
|> then(&Application.put_env(:toxiproxy_ex, :host, &1))
"""
def api_url(%Container{} = container) do
host = Testcontainers.get_host()
host = Testcontainers.get_host(container)
port = mapped_control_port(container)
"http://#{host}:#{port}"
end
Expand Down Expand Up @@ -130,7 +130,7 @@ defmodule Testcontainers.ToxiproxyContainer do
def create_proxy(%Container{} = container, name, upstream, opts \\ []) do
listen_port = Keyword.get(opts, :listen_port, @first_proxy_port)

host = Testcontainers.get_host()
host = Testcontainers.get_host(container)
api_port = mapped_control_port(container)

:inets.start()
Expand All @@ -149,11 +149,11 @@ defmodule Testcontainers.ToxiproxyContainer do
case httpc_request_with_retry(:post, {url, headers, ~c"application/json", body}) do
{:ok, {{_, code, _}, _, _}} when code in [200, 201] ->
# Return the mapped port on the host
{:ok, Container.mapped_port(container, listen_port)}
{:ok, Testcontainers.get_port(container, listen_port)}

{:ok, {{_, 409, _}, _, _}} ->
# Proxy already exists, return the port
{:ok, Container.mapped_port(container, listen_port)}
{:ok, Testcontainers.get_port(container, listen_port)}

{:ok, {{_, code, _}, _, response_body}} ->
{:error, {:http_error, code, response_body}}
Expand Down Expand Up @@ -193,7 +193,7 @@ defmodule Testcontainers.ToxiproxyContainer do
Deletes a proxy from Toxiproxy.
"""
def delete_proxy(%Container{} = container, name) do
host = Testcontainers.get_host()
host = Testcontainers.get_host(container)
api_port = mapped_control_port(container)

:inets.start()
Expand All @@ -212,7 +212,7 @@ defmodule Testcontainers.ToxiproxyContainer do
Resets Toxiproxy, removing all toxics and re-enabling all proxies.
"""
def reset(%Container{} = container) do
host = Testcontainers.get_host()
host = Testcontainers.get_host(container)
api_port = mapped_control_port(container)

:inets.start()
Expand All @@ -232,7 +232,7 @@ defmodule Testcontainers.ToxiproxyContainer do
Returns a map of proxy names to their configurations.
"""
def list_proxies(%Container{} = container) do
host = Testcontainers.get_host()
host = Testcontainers.get_host(container)
api_port = mapped_control_port(container)

:inets.start()
Expand Down
10 changes: 5 additions & 5 deletions lib/mix/tasks/testcontainers/run.ex
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ defmodule Mix.Tasks.Testcontainers.Run do

{:ok, container} = Testcontainers.start_container(container_def)
port = PostgresContainer.port(container)
{container, create_env(port)}
{container, create_env(container, port)}

"mysql" ->
container_def =
Expand All @@ -89,7 +89,7 @@ defmodule Mix.Tasks.Testcontainers.Run do

{:ok, container} = Testcontainers.start_container(container_def)
port = MySqlContainer.port(container)
{container, create_env(port)}
{container, create_env(container, port)}

_ ->
raise("Unsupported database: #{database}")
Expand All @@ -108,13 +108,13 @@ defmodule Mix.Tasks.Testcontainers.Run do
module.with_persistent_volume(config, db_volume)
end

defp create_env(port) do
defp create_env(container, port) do
[
{"DATABASE_URL", "ecto://test:test@#{Testcontainers.get_host()}:#{port}/test"},
{"DATABASE_URL", "ecto://test:test@#{Testcontainers.get_host(container)}:#{port}/test"},
# for backward compability, will be removed in future releases
{"DB_USER", "test"},
{"DB_PASSWORD", "test"},
{"DB_HOST", Testcontainers.get_host()},
{"DB_HOST", Testcontainers.get_host(container)},
{"DB_PORT", Integer.to_string(port)}
]
end
Expand Down
Loading
Loading