e9d1a13900
Refs EventHub/EventHubBack#37 Refs EventHub/EventHubBack#38 Refs EventHub/EventHubBack#39 Refs EventHub/EventHubBack#40
186 lines
5.6 KiB
Erlang
186 lines
5.6 KiB
Erlang
%%%-------------------------------------------------------------------
|
|
%%% @doc Common Test Suite для клиентского API.
|
|
%%%
|
|
%%% Поддерживает два режима запуска:
|
|
%%% - Локальный (CT_MODE=local или не задан): автоматически
|
|
%%% стартует EventHub, выполняет тесты и останавливает приложение.
|
|
%%% - Удалённый (CT_MODE=remote): подключается к уже работающему
|
|
%%% кластеру по URL, определённым в переменных окружения
|
|
%%% (API_HOST, ADMIN_API_HOST и т.д.).
|
|
%%%
|
|
%%% Запуск:
|
|
%%% rebar3 ct --suite=api_client_SUITE
|
|
%%% или CT_MODE=remote rebar3 ct --suite=api_client_SUITE
|
|
%%% @end
|
|
%%%-------------------------------------------------------------------
|
|
-module(api_users_SUITE).
|
|
-compile(export_all).
|
|
|
|
-include_lib("common_test/include/ct.hrl").
|
|
|
|
%%%===================================================================
|
|
%%% Common Test callbacks
|
|
%%%===================================================================
|
|
|
|
%% @doc Возвращает список тестовых кейсов.
|
|
all() ->
|
|
[
|
|
user_test_verification,
|
|
user_test_register,
|
|
user_test_login,
|
|
user_test_user_me,
|
|
user_test_calendars,
|
|
user_test_calendar_by_id,
|
|
user_test_calendar_view,
|
|
user_test_event_by_id,
|
|
user_test_events,
|
|
user_test_occurrence_cancel,
|
|
user_test_bookings,
|
|
user_test_my_bookings,
|
|
user_test_reviews,
|
|
user_test_review_by_id,
|
|
user_test_my_reviews,
|
|
user_test_search,
|
|
user_test_refresh,
|
|
user_test_reports,
|
|
user_test_automod,
|
|
user_test_tickets,
|
|
user_test_subscription,
|
|
user_test_websocket
|
|
].
|
|
|
|
%% @doc Инициализация сьюта.
|
|
%% В локальном режиме запускает приложение EventHub.
|
|
init_per_suite(Config) ->
|
|
case os:getenv("CT_MODE", "local") of
|
|
"remote" ->
|
|
ct:pal("Remote mode: assuming application is already running"),
|
|
inets:start(),
|
|
ssl:start(),
|
|
% Отключаем авто-редирект и проверку сертификатов
|
|
httpc:set_options([
|
|
{autoredirect, false},
|
|
{ssl, [{verify, verify_none}]}
|
|
]),
|
|
wait_for_remote(),
|
|
[{started_by_us, false} | Config];
|
|
_ ->
|
|
case lists:keymember(eventhub, 1, application:which_applications()) of
|
|
true ->
|
|
ct:pal("Local mode: application already running"),
|
|
[{started_by_us, false} | Config];
|
|
false ->
|
|
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]
|
|
end
|
|
end.
|
|
|
|
%% @doc Завершение сьюта. В локальном режиме останавливает приложение.
|
|
end_per_suite(Config) ->
|
|
case proplists:get_value(started_by_us, Config, false) andalso
|
|
os:getenv("CT_MODE", "local") =/= "remote" of
|
|
true ->
|
|
application:stop(eventhub);
|
|
false ->
|
|
ok
|
|
end,
|
|
Config.
|
|
|
|
%%%===================================================================
|
|
%%% Тестовые кейсы
|
|
%%%===================================================================
|
|
|
|
%% @doc Тесты регистрации.
|
|
user_test_verification(_Config) ->
|
|
user_verification_tests:test().
|
|
|
|
user_test_register(_Config) ->
|
|
user_register_tests:test().
|
|
|
|
user_test_login(_Config) ->
|
|
user_login_tests:test().
|
|
|
|
user_test_user_me(_Config) ->
|
|
user_me_tests:test().
|
|
|
|
user_test_calendars(_Config) ->
|
|
user_calendars_tests:test().
|
|
|
|
user_test_calendar_by_id(_Config) ->
|
|
user_calendar_by_id_tests:test().
|
|
|
|
user_test_calendar_view(_Config) ->
|
|
user_calendar_view_tests:test().
|
|
|
|
user_test_events(_Config) ->
|
|
user_events_tests:test().
|
|
|
|
user_test_event_by_id(_Config) ->
|
|
user_event_by_id_tests:test().
|
|
|
|
user_test_occurrence_cancel(_Config) ->
|
|
user_occurrence_cancel_tests:test().
|
|
|
|
user_test_bookings(_Config) ->
|
|
user_bookings_tests:test().
|
|
|
|
user_test_my_bookings(_Config) ->
|
|
user_my_bookings_tests:test().
|
|
|
|
user_test_reviews(_Config) ->
|
|
user_reviews_tests:test().
|
|
|
|
user_test_review_by_id(_Config) ->
|
|
user_review_by_id_tests:test().
|
|
|
|
user_test_my_reviews(_Config) ->
|
|
user_my_reviews_tests:test().
|
|
|
|
user_test_search(_Config) ->
|
|
user_search_tests:test().
|
|
|
|
user_test_refresh(_Config) ->
|
|
user_refresh_tests:test().
|
|
|
|
user_test_reports(_Config) ->
|
|
user_reports_tests:test().
|
|
|
|
user_test_automod(_Config) ->
|
|
user_automod_tests:test().
|
|
|
|
user_test_tickets(_Config) ->
|
|
user_tickets_tests:test().
|
|
|
|
user_test_subscription(_Config) ->
|
|
user_subscription_tests:test().
|
|
|
|
user_test_websocket(_Config) ->
|
|
user_websocket_tests:test().
|
|
|
|
%%%===================================================================
|
|
%%% Внутренние функции
|
|
%%%===================================================================
|
|
|
|
-spec ct_mode() -> string().
|
|
ct_mode() ->
|
|
os:getenv("CT_MODE", "local").
|
|
|
|
%% @private Ожидание доступности удалённого API.
|
|
-spec wait_for_remote() -> ok.
|
|
wait_for_remote() ->
|
|
URL = api_test_runner:get_base_url() ++ "/health",
|
|
ct:pal("Waiting for remote API: ~s", [URL]),
|
|
wait_for_health(URL, 30).
|
|
|
|
wait_for_health(_URL, 0) ->
|
|
ct:fail("Remote API did not start within 30 seconds");
|
|
wait_for_health(URL, Retries) ->
|
|
case httpc:request(get, {URL, []}, [{timeout, 5000}, {ssl, [{verify, verify_none}]}], []) of
|
|
{ok, {{_, 200, _}, _, _}} -> ok;
|
|
_ ->
|
|
timer:sleep(1000),
|
|
wait_for_health(URL, Retries - 1)
|
|
end. |