Packages

Gleam TestContainers wrapper around Elixir TestContainers

Current section

Files

Jump to
testcontainers_gleam src testcontainers_gleam@wait_strategy.erl
Raw

src/testcontainers_gleam@wait_strategy.erl

-module(testcontainers_gleam@wait_strategy).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/testcontainers_gleam/wait_strategy.gleam").
-export([port/4, command/3, log/3]).
-export_type([wait_strategy/0, regex/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
" Wait strategies to determine when a container is ready.\n"
"\n"
" A wait strategy is passed to `container.with_waiting_strategy` to tell\n"
" testcontainers how to detect that a container has finished starting.\n"
"\n"
" ## Example\n"
"\n"
" ```gleam\n"
" import testcontainers_gleam/container\n"
" import testcontainers_gleam/wait_strategy\n"
"\n"
" container.new(\"postgres:16-alpine\")\n"
" |> container.with_exposed_port(5432)\n"
" |> container.with_waiting_strategy(\n"
" wait_strategy.port(\"0.0.0.0\", 5432, 5000, 500),\n"
" )\n"
" ```\n"
).
-type wait_strategy() :: any().
-type regex() :: any().
-file("src/testcontainers_gleam/wait_strategy.gleam", 28).
?DOC(
" Wait until the given `port` on `ip` accepts TCP connections.\n"
"\n"
" Retries every `retry_delay` ms, giving up after `timeout` ms.\n"
).
-spec port(binary(), integer(), integer(), integer()) -> wait_strategy().
port(Ip, Port, Timeout, Retry_delay) ->
'Elixir.Testcontainers.PortWaitStrategy':new(Ip, Port, Timeout, Retry_delay).
-file("src/testcontainers_gleam/wait_strategy.gleam", 49).
?DOC(
" Wait until `command` exits with status 0 inside the container.\n"
"\n"
" Retries every `retry_delay` ms, giving up after `timeout` ms.\n"
).
-spec command(list(binary()), integer(), integer()) -> wait_strategy().
command(Cmd, Timeout, Retry_delay) ->
'Elixir.Testcontainers.CommandWaitStrategy':new(Cmd, Timeout, Retry_delay).
-file("src/testcontainers_gleam/wait_strategy.gleam", 40).
?DOC(
" Wait until a container log line matches `pattern`.\n"
"\n"
" The pattern is compiled to an Elixir Regex before being passed to\n"
" the underlying `LogWaitStrategy`. Retries every `retry_delay` ms,\n"
" giving up after `timeout` ms.\n"
).
-spec log(binary(), integer(), integer()) -> wait_strategy().
log(Pattern, Timeout, Retry_delay) ->
Regex = 'Elixir.Regex':'compile!'(Pattern),
'Elixir.Testcontainers.LogWaitStrategy':new(Regex, Timeout, Retry_delay).