Skip to content

Commit

Permalink
simplify strategy execution
Browse files Browse the repository at this point in the history
  • Loading branch information
jarlah committed Oct 15, 2023
1 parent 39748dc commit c8eb354
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
26 changes: 11 additions & 15 deletions lib/docker/api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule Testcontainers.Docker.Api do

def run(%Container{} = container_config, options \\ []) do
on_exit = Keyword.get(options, :on_exit, nil)
wait_strategies = container_config.wait_strategies
wait_strategies = container_config.wait_strategies || []
create_request = container_create_request(container_config)

with :ok <- pull_image(create_request."Image", recv_timeout: 60_000),
Expand All @@ -25,20 +25,16 @@ defmodule Testcontainers.Docker.Api do
end),
{:ok, container} <- get_container(id),
:ok <-
if(!Enum.empty?(wait_strategies),
do:
Enum.reduce(wait_strategies, :ok, fn
wait_strategy, :ok ->
WaitStrategy.wait_until_container_is_ready(
wait_strategy,
container.container_id
)

_, error ->
error
end),
else: :ok
) do
Enum.reduce(wait_strategies, :ok, fn
wait_strategy, :ok ->
WaitStrategy.wait_until_container_is_ready(
wait_strategy,
container.container_id
)

_, error ->
error
end) do
{:ok, container}
else
{:error, other} -> {:error, other}
Expand Down
2 changes: 2 additions & 0 deletions test/selenium_container_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ defmodule Testcontainers.SeleniumContainerTest do
container(:selenium, SeleniumContainer.new())

test "provides a ready-to-use selenium container", %{selenium: selenium} do
assert Container.mapped_port(selenium, 4400) > 0
assert Container.mapped_port(selenium, 4400) != 4400
assert Container.mapped_port(selenium, 7900) > 0
assert Container.mapped_port(selenium, 7900) != 7900
end
end
Expand Down

0 comments on commit c8eb354

Please sign in to comment.