test(api): CT на портах 18080/18445 вне docker-dev [skip ci]
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
get_base_url/0,
|
||||
get_base_ws_url/0,
|
||||
get_admin_ws_url/0,
|
||||
ensure_local_app_ports/0,
|
||||
get_admin_token/0,
|
||||
get_superadmin_token/0,
|
||||
get_moderator_token/0,
|
||||
@@ -57,32 +58,68 @@ ct_mode() ->
|
||||
|
||||
-spec get_base_url() -> string().
|
||||
get_base_url() ->
|
||||
case ct_mode() of
|
||||
"remote" -> os:getenv("API_HOST", "http://localhost:8080");
|
||||
_ -> "http://localhost:8080"
|
||||
end.
|
||||
os:getenv("API_HOST", "http://localhost:18080").
|
||||
|
||||
-spec get_admin_url() -> string().
|
||||
get_admin_url() ->
|
||||
case ct_mode() of
|
||||
"remote" -> os:getenv("ADMIN_API_HOST", "http://localhost:8445");
|
||||
_ -> "http://localhost:8445"
|
||||
end.
|
||||
os:getenv("ADMIN_API_HOST", "http://localhost:18445").
|
||||
|
||||
-spec get_base_ws_url() -> string().
|
||||
get_base_ws_url() ->
|
||||
case ct_mode() of
|
||||
"remote" -> os:getenv("WS_HOST", "ws://localhost:8081");
|
||||
_ -> "ws://localhost:8081"
|
||||
end.
|
||||
os:getenv("WS_HOST", "ws://localhost:18081").
|
||||
|
||||
-spec get_admin_ws_url() -> string().
|
||||
get_admin_ws_url() ->
|
||||
case ct_mode() of
|
||||
"remote" -> os:getenv("ADMIN_WS_HOST", "ws://localhost:8446");
|
||||
_ -> "ws://localhost:8446"
|
||||
os:getenv("ADMIN_WS_HOST", "ws://localhost:18446").
|
||||
|
||||
%% @doc Порты CT-local (не docker 8080/8445). Вызывать до ensure_all_started(eventhub).
|
||||
-spec ensure_local_app_ports() -> ok.
|
||||
ensure_local_app_ports() ->
|
||||
_ = application:load(eventhub),
|
||||
_ = application:load(mnesia),
|
||||
application:set_env(eventhub, http_port, env_port("HTTP_PORT", 18080)),
|
||||
application:set_env(eventhub, ws_port, env_port("WS_PORT", 18081)),
|
||||
application:set_env(eventhub, admin_http_port, env_port("ADMIN_HTTP_PORT", 18445)),
|
||||
application:set_env(eventhub, admin_ws_port, env_port("ADMIN_WS_PORT", 18446)),
|
||||
application:set_env(eventhub, swagger_http_port, env_port("SWAGGER_HTTP_PORT", 18447)),
|
||||
ensure_fresh_mnesia_dir(),
|
||||
clear_cached_admin_tokens(),
|
||||
ok.
|
||||
|
||||
env_port(Name, Default) ->
|
||||
case os:getenv(Name) of
|
||||
false -> Default;
|
||||
"" -> Default;
|
||||
Val -> list_to_integer(Val)
|
||||
end.
|
||||
|
||||
ensure_fresh_mnesia_dir() ->
|
||||
%% Absolute path under WSL data (CT cwd is logs/test/ct/ct_run.* — relative data/ is missing).
|
||||
Dir = filename:join([
|
||||
os:getenv("HOME", "/home/alexc"),
|
||||
"eventhub-wsl-data", "data", "mnesia_ct"
|
||||
]),
|
||||
_ = application:load(mnesia),
|
||||
application:set_env(mnesia, dir, Dir),
|
||||
_ = (catch mnesia:stop()),
|
||||
ok = filelib:ensure_dir(filename:join(Dir, ".keep")),
|
||||
_ = file:del_dir_r(Dir),
|
||||
_ = (catch mnesia:delete_schema([node()])),
|
||||
case mnesia:create_schema([node()]) of
|
||||
ok ->
|
||||
ok;
|
||||
{error, {already_exists, _}} ->
|
||||
ok;
|
||||
{error, Reason} ->
|
||||
error({ct_mnesia_create_schema_failed, Reason, Dir, node()})
|
||||
end.
|
||||
|
||||
clear_cached_admin_tokens() ->
|
||||
lists:foreach(
|
||||
fun(Role) -> _ = persistent_term:erase({?MODULE, admin_token, Role}) end,
|
||||
[admin, superadmin, moderator, support]
|
||||
).
|
||||
|
||||
%%%===================================================================
|
||||
%%% Учётные данные администраторов (из переменных окружения)
|
||||
%%%===================================================================
|
||||
|
||||
@@ -63,7 +63,8 @@ init_per_suite(Config) ->
|
||||
ct:pal("Local mode: application already running"),
|
||||
[{started_by_us, false} | Config];
|
||||
false ->
|
||||
ct:pal("Local mode: starting application..."),
|
||||
ct:pal("Local mode: starting application on CT ports (18080/18445)..."),
|
||||
ok = api_test_runner:ensure_local_app_ports(),
|
||||
{ok, _} = application:ensure_all_started(eventhub),
|
||||
timer:sleep(1000),
|
||||
[{started_by_us, true} | Config]
|
||||
@@ -142,7 +143,7 @@ ct_mode() ->
|
||||
%% @private Ожидание доступности удалённого API.
|
||||
-spec wait_for_remote() -> ok.
|
||||
wait_for_remote() ->
|
||||
URL = os:getenv("ADMIN_API_HOST", "http://localhost:8445") ++ "/admin/health",
|
||||
URL = api_test_runner:get_admin_url() ++ "/admin/health",
|
||||
ct:pal("Waiting for remote API: ~s", [URL]),
|
||||
wait_for_health(URL, 30).
|
||||
|
||||
|
||||
@@ -69,7 +69,8 @@ init_per_suite(Config) ->
|
||||
ct:pal("Local mode: application already running"),
|
||||
[{started_by_us, false} | Config];
|
||||
false ->
|
||||
ct:pal("Local mode: starting application..."),
|
||||
ct:pal("Local mode: starting application on CT ports (18080/18445)..."),
|
||||
ok = api_test_runner:ensure_local_app_ports(),
|
||||
{ok, _} = application:ensure_all_started(eventhub),
|
||||
timer:sleep(1000),
|
||||
[{started_by_us, true} | Config]
|
||||
@@ -166,7 +167,7 @@ ct_mode() ->
|
||||
%% @private Ожидание доступности удалённого API.
|
||||
-spec wait_for_remote() -> ok.
|
||||
wait_for_remote() ->
|
||||
URL = os:getenv("API_HOST", "http://localhost:8080") ++ "/health",
|
||||
URL = api_test_runner:get_base_url() ++ "/health",
|
||||
ct:pal("Waiting for remote API: ~s", [URL]),
|
||||
wait_for_health(URL, 30).
|
||||
|
||||
|
||||
Reference in New Issue
Block a user