test(exhook): customized hooks priority

This commit is contained in:
JimMoen 2022-03-25 11:22:45 +08:00
parent b7f10b67a8
commit 1a57d0d2ca
1 changed files with 21 additions and 0 deletions

View File

@ -98,10 +98,31 @@ t_cli_stats(_) ->
_ = emqx_exhook_cli:cli(x), _ = emqx_exhook_cli:cli(x),
unmeck_print(). unmeck_print().
t_priority(_) ->
restart_exhook_with_envs([{emqx_exhook, hook_priority, 1}]),
emqx_exhook:disable(default),
ok = emqx_exhook:enable(default),
[Callback | _] = emqx_hooks:lookup('client.connected'),
1 = emqx_hooks:callback_priority(Callback).
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Utils %% Utils
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% TODO: make it more general and move to `emqx_ct_helpers`
restart_exhook_with_envs(Envs) ->
emqx_ct_helpers:stop_apps([emqx_exhook]),
SetPriorityFun
= fun(emqx) ->
set_special_cfgs(emqx);
(emqx_exhook) ->
lists:foreach(fun({App, Key, Val}) ->
application:set_env(App, Key, Val)
end, Envs)
end,
emqx_ct_helpers:start_apps([emqx_exhook], SetPriorityFun).
meck_print() -> meck_print() ->
meck:new(emqx_ctl, [passthrough, no_history, no_link]), meck:new(emqx_ctl, [passthrough, no_history, no_link]),
meck:expect(emqx_ctl, print, fun(_) -> ok end), meck:expect(emqx_ctl, print, fun(_) -> ok end),