Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jarlah committed Oct 13, 2023
1 parent f3e7553 commit fc32df2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
9 changes: 6 additions & 3 deletions lib/http_checker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ defmodule TestcontainersElixir.HttpChecker do
end

defp wait_for_http(ip, port, path, timeout, start_time)
when is_binary(ip) and is_integer(port) and is_binary(path) and is_integer(timeout) and is_integer(start_time) do
when is_binary(ip) and is_integer(port) and is_binary(path) and is_integer(timeout) and
is_integer(start_time) do
if timeout + start_time < :os.system_time(:millisecond) do
{:error, :timeout}
else
Expand All @@ -33,11 +34,13 @@ defmodule TestcontainersElixir.HttpChecker do

defp http_request(ip, port, path) do
url = "http://" <> ip <> ":" <> Integer.to_string(port) <> path

case :httpc.request(:get, {to_charlist(url), []}, [], []) do
{:ok, {{'HTTP/1.1', 200, _reason_phrase}, _headers, _body}} ->
{:ok, {{~c"HTTP/1.1", 200, _reason_phrase}, _headers, _body}} ->
{:ok, :http_ok}

{:ok, {{'HTTP/1.1', status_code, _reason_phrase}, _headers, _body}} when status_code != 200 ->
{:ok, {{~c"HTTP/1.1", status_code, _reason_phrase}, _headers, _body}}
when status_code != 200 ->
{:error, {:unexpected_status_code, status_code}}

{:error, reason} ->
Expand Down
7 changes: 1 addition & 6 deletions test/simple_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ defmodule SimpleTest do
port = Container.mapped_port(container, 80)
{:ok, :http_is_ready} = HttpChecker.wait_for_http("127.0.0.1", port, "/", 5000)

{:ok, 200, _headers, body_ref} =
:hackney.request(:get, "http://127.0.0.1:#{port}",
follow_redirect: true,
max_redirect: 1,
force_redirect: true
)
{:ok, 200, _headers, body_ref} = :hackney.request(:get, "http://127.0.0.1:#{port}")

{:ok, body} = :hackney.body(body_ref)
body_str = IO.iodata_to_binary(body)
Expand Down

0 comments on commit fc32df2

Please sign in to comment.