38 lines
1.1 KiB
Erlang
38 lines
1.1 KiB
Erlang
-module(admin_handler_health_tests).
|
||
-include_lib("eunit/include/eunit.hrl").
|
||
|
||
setup() ->
|
||
ok.
|
||
|
||
cleanup(_) ->
|
||
eh_test_support:unload_cowboy(),
|
||
ok.
|
||
|
||
admin_health_test_() ->
|
||
{foreach, fun setup/0, fun cleanup/1, [
|
||
{"GET health – success", fun test_health_get/0},
|
||
{"POST health – method not allowed", fun test_health_wrong_method/0}
|
||
]}.
|
||
|
||
test_health_get() ->
|
||
{Status, _, Body} = eh_test_support:call(admin_handler_health, #{
|
||
method => <<"GET">>,
|
||
path => <<"/admin/health">>,
|
||
auth => none
|
||
}),
|
||
?assertEqual(200, Status),
|
||
Result = jsx:decode(Body, [return_maps]),
|
||
?assertEqual(<<"ok">>, maps:get(<<"status">>, Result)),
|
||
?assertEqual(<<"eventhub">>, maps:get(<<"service">>, Result)),
|
||
?assert(is_map_key(<<"version">>, Result)),
|
||
?assert(is_map_key(<<"git_sha">>, Result)).
|
||
|
||
test_health_wrong_method() ->
|
||
{Status, _, Body} = eh_test_support:call(admin_handler_health, #{
|
||
method => <<"POST">>,
|
||
path => <<"/admin/health">>,
|
||
auth => none
|
||
}),
|
||
?assertEqual(405, Status),
|
||
#{<<"error">> := <<"Method not allowed">>} = jsx:decode(Body, [return_maps]).
|