test(mongo): add more coverage tests

reaching 100% coverage of `emqx_auth_mongo` with this.
This commit is contained in:
Thales Macedo Garitezi 2022-09-20 14:08:33 -03:00
parent 3f02c6b574
commit 69659caaf8
1 changed files with 24 additions and 1 deletions

View File

@ -340,7 +340,7 @@ t_available(Config) ->
?assertEqual( ?assertEqual(
{error, {mongo_error, 2}}, {error, {mongo_error, 2}},
emqx_auth_mongo:available(Pool, SuperCollection, EmptySelector, fun error_code_query/3)), emqx_auth_mongo:available(Pool, SuperCollection, EmptySelector, fun error_code_query/3)),
%% exception. %% exception (in query)
?assertMatch( ?assertMatch(
{error, _}, {error, _},
with_failure(down, ProxyHost, ProxyPort, with_failure(down, ProxyHost, ProxyPort,
@ -349,6 +349,16 @@ t_available(Config) ->
Selector = #{}, Selector = #{},
emqx_auth_mongo:available(Pool, Collection, Selector) emqx_auth_mongo:available(Pool, Collection, Selector)
end)), end)),
%% exception (arbitrary function)
?assertMatch(
{error, _},
with_failure(down, ProxyHost, ProxyPort,
fun() ->
Collection = <<"mqtt_user">>,
Selector = #{},
RaisingFun = fun(_, _, _) -> error(some_error) end,
emqx_auth_mongo:available(Pool, Collection, Selector, RaisingFun)
end)),
ok. ok.
t_check_acl(_) -> t_check_acl(_) ->
@ -430,6 +440,19 @@ t_available_acl_query_timeout(Config) ->
ct:timetrap(90000), ct:timetrap(90000),
test_acl_query_failure(timeout, Config). test_acl_query_failure(timeout, Config).
%% checks that `with_timeout' lets unknown errors pass through
t_query_multi_unknown_exception(_Config) ->
ok = meck:new(ecpool, [no_link, no_history, non_strict, passthrough]),
ok = meck:expect(ecpool, with_client, fun(_, _) -> throw(some_error) end),
Pool = ?APP,
Collection = ?MONGO_CL_ACL,
SelectorList = [#{<<"username">> => <<"user">>}],
try
?assertThrow(some_error, emqx_auth_mongo:query_multi(Pool, Collection, SelectorList))
after
meck:unload(ecpool)
end.
t_acl_superuser_no_connection(Config) -> t_acl_superuser_no_connection(Config) ->
ProxyHost = ?config(proxy_host, Config), ProxyHost = ?config(proxy_host, Config),
ProxyPort = ?config(proxy_port, Config), ProxyPort = ?config(proxy_port, Config),