Rewrite and expand EUnit suite; run unit tests in CI from shared test image. Refs EventHub/EventHubBack#36 [skip ci]

This commit is contained in:
2026-07-17 15:16:46 +03:00
parent 9d2780fef4
commit 4fa802702f
54 changed files with 4240 additions and 2281 deletions
+19 -16
View File
@@ -2,17 +2,16 @@
-include_lib("eunit/include/eunit.hrl").
-include("records.hrl").
-define(TABLES, [event]).
setup() ->
mnesia:start(),
mnesia:create_table(event, [
{attributes, record_info(fields, event)},
{ram_copies, [node()]}
]),
eh_test_support:start_mnesia(),
eh_test_support:ensure_tables(?TABLES),
ok.
cleanup(_) ->
mnesia:delete_table(event),
mnesia:stop(),
eh_test_support:delete_tables(?TABLES),
eh_test_support:stop_mnesia(),
ok.
core_event_test_() ->
@@ -27,10 +26,14 @@ core_event_test_() ->
{"Delete event test", fun test_delete_event/0}
]}.
add_days(DateTime, Days) ->
Sec = calendar:datetime_to_gregorian_seconds(DateTime) + Days * 86400,
calendar:gregorian_seconds_to_datetime(Sec).
test_create_event() ->
CalendarId = <<"calendar123">>,
Title = <<"Test Event">>,
StartTime = {{2026, 4, 25}, {10, 0, 0}},
StartTime = eh_test_support:future_start(),
Duration = 60,
{ok, Event} = core_event:create(CalendarId, Title, StartTime, Duration),
@@ -48,7 +51,7 @@ test_create_event() ->
test_get_by_id() ->
CalendarId = <<"calendar123">>,
{ok, Event} = core_event:create(CalendarId, <<"Test">>, {{2026, 4, 25}, {10, 0, 0}}, 60),
{ok, Event} = core_event:create(CalendarId, <<"Test">>, eh_test_support:future_start(), 60),
{ok, Found} = core_event:get_by_id(Event#event.id),
?assertEqual(Event#event.id, Found#event.id),
@@ -58,10 +61,11 @@ test_get_by_id() ->
test_list_by_calendar() ->
CalendarId1 = <<"calendar1">>,
CalendarId2 = <<"calendar2">>,
Base = eh_test_support:future_start(),
{ok, _} = core_event:create(CalendarId1, <<"Event 1">>, {{2026, 4, 25}, {10, 0, 0}}, 60),
{ok, _} = core_event:create(CalendarId1, <<"Event 2">>, {{2026, 4, 26}, {11, 0, 0}}, 90),
{ok, _} = core_event:create(CalendarId2, <<"Event 3">>, {{2026, 4, 27}, {12, 0, 0}}, 30),
{ok, _} = core_event:create(CalendarId1, <<"Event 1">>, Base, 60),
{ok, _} = core_event:create(CalendarId1, <<"Event 2">>, add_days(Base, 1), 90),
{ok, _} = core_event:create(CalendarId2, <<"Event 3">>, add_days(Base, 2), 30),
{ok, Events1} = core_event:list_by_calendar(CalendarId1),
?assertEqual(2, length(Events1)),
@@ -74,7 +78,7 @@ test_list_by_calendar() ->
test_update_event() ->
CalendarId = <<"calendar123">>,
{ok, Event} = core_event:create(CalendarId, <<"Original">>, {{2026, 4, 25}, {10, 0, 0}}, 60),
{ok, Event} = core_event:create(CalendarId, <<"Original">>, eh_test_support:future_start(), 60),
timer:sleep(2000),
Updates = [{title, <<"Updated">>}, {capacity, 100}, {description, <<"New desc">>}],
{ok, Updated} = core_event:update(Event#event.id, Updates),
@@ -88,11 +92,10 @@ test_update_event() ->
test_delete_event() ->
CalendarId = <<"calendar123">>,
{ok, Event} = core_event:create(CalendarId, <<"Test">>, {{2026, 4, 25}, {10, 0, 0}}, 60),
{ok, Event} = core_event:create(CalendarId, <<"Test">>, eh_test_support:future_start(), 60),
{ok, Deleted} = core_event:delete(Event#event.id),
?assertEqual(deleted, Deleted#event.status),
% Удалённое событие не возвращается в списке активных
{ok, ActiveEvents} = core_event:list_by_calendar(CalendarId),
?assertEqual(0, length(ActiveEvents)).
?assertEqual(0, length(ActiveEvents)).