Current section
Files
Jump to
Current section
Files
src/testcontainers_gleam@integration.erl
-module(testcontainers_gleam@integration).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/testcontainers_gleam/integration.gleam").
-export([guard/1, main_with_timeout/1, main/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(
" Utilities for running testcontainers integration tests.\n"
"\n"
" Provides a test runner with per-test timeouts suitable for container\n"
" startup, and a guard function to skip tests when Docker is not available.\n"
"\n"
" ## Usage\n"
"\n"
" Replace `gleeunit.main()` with `integration.main()` in your test entry\n"
" point, and use `integration.guard()` to gate individual tests behind the\n"
" `TESTCONTAINERS_INTEGRATION_TESTS` environment variable:\n"
"\n"
" ```gleam\n"
" import testcontainers_gleam/integration\n"
"\n"
" pub fn main() {\n"
" integration.main()\n"
" }\n"
"\n"
" pub fn redis_test() {\n"
" use <- integration.guard()\n"
" // ... start container, run assertions ...\n"
" }\n"
" ```\n"
).
-file("src/testcontainers_gleam/integration.gleam", 81).
?DOC(
" Gate a test behind the `TESTCONTAINERS_INTEGRATION_TESTS` environment\n"
" variable. When the variable is not set, the test body is skipped and\n"
" `Nil` is returned.\n"
"\n"
" ## Examples\n"
"\n"
" ```gleam\n"
" pub fn redis_test() {\n"
" use <- integration.guard()\n"
" // ... start container, run assertions ...\n"
" }\n"
" ```\n"
).
-spec guard(fun(() -> nil)) -> nil.
guard(Test_fn) ->
case envoy_ffi:get(<<"TESTCONTAINERS_INTEGRATION_TESTS"/utf8>>) of
{ok, _} ->
Test_fn();
{error, _} ->
nil
end.
-file("src/testcontainers_gleam/integration.gleam", 60).
?DOC(
" Run all tests with a custom per-test timeout in seconds.\n"
"\n"
" Automatically sets `TESTCONTAINERS_RYUK_DISABLED=1` so the Ryuk sidecar\n"
" container is not started.\n"
"\n"
" ## Examples\n"
"\n"
" ```gleam\n"
" import testcontainers_gleam/integration\n"
"\n"
" pub fn main() {\n"
" integration.main_with_timeout(120)\n"
" }\n"
" ```\n"
).
-spec main_with_timeout(integer()) -> nil.
main_with_timeout(Timeout_seconds) ->
envoy_ffi:set(<<"TESTCONTAINERS_RYUK_DISABLED"/utf8>>, <<"1"/utf8>>),
Code = case integration_ffi:run(Timeout_seconds) of
{ok, _} ->
0;
{error, _} ->
1
end,
erlang:halt(Code).
-file("src/testcontainers_gleam/integration.gleam", 42).
?DOC(
" Run all tests with a 600-second per-test timeout.\n"
"\n"
" Automatically sets `TESTCONTAINERS_RYUK_DISABLED=1` so the Ryuk sidecar\n"
" container is not started. This is a drop-in replacement for\n"
" `gleeunit.main()`.\n"
"\n"
" ## Examples\n"
"\n"
" ```gleam\n"
" import testcontainers_gleam/integration\n"
"\n"
" pub fn main() {\n"
" integration.main()\n"
" }\n"
" ```\n"
).
-spec main() -> nil.
main() ->
main_with_timeout(600).