Skip to content

Commit

Permalink
fix docker host from env
Browse files Browse the repository at this point in the history
  • Loading branch information
jarlah committed Oct 26, 2023
1 parent 20fac04 commit 829c229
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions lib/connection/docker_host_strategy/docker_host_from_env.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,26 @@
defmodule Testcontainers.Connection.DockerHostStrategy.DockerHostFromEnv do
defstruct key: "DOCKER_HOST"

alias Testcontainers.DockerUrl

defimpl Testcontainers.Connection.DockerHostStrategy do
def execute(strategy, _input) do
with {:ok, docker_host} <- get_docker_host(strategy) do
test_docker_host(docker_host)
end
end

defp test_docker_host(docker_host) do
case docker_host |> DockerUrl.construct() |> DockerUrl.test_docker_connection() do
:ok ->
{:ok, docker_host}

{:error, reason} ->
{:error, docker_host_from_env: reason}
end
end

defp get_docker_host(strategy) do
case System.get_env(strategy.key) do
nil ->
{:error, docker_host_from_env: :docker_host_not_found}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule Testcontainers.Connection.DockerHostStrategy.DockerHostFromEnvTest do
test "should return ok if env exists" do
strategy = %DockerHostFromEnv{key: "X_DOCKER_HOST"}

{:ok, "tcp://somehostname:9876"} =
{:error, docker_host_from_env: :econnrefused} =
DockerHostStrategyEvaluator.run_strategies([strategy], [])
end

Expand Down

0 comments on commit 829c229

Please sign in to comment.