Skip to content

Commit

Permalink
Replace global config with local config in small tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chrzaszcz committed Oct 14, 2021
1 parent c623503 commit ce7f288
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 52 deletions.
14 changes: 7 additions & 7 deletions test/acl_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ different_specs_matching_the_same_user(Config) ->
ok.

set_acl(HostType, ACLName, ACLSpec) ->
ejabberd_config:add_global_option({acl, ACLName, HostType}, [ACLSpec]).
ejabberd_config:add_local_option({acl, ACLName, HostType}, [ACLSpec]).

given_clean_config() ->
meck:unload(),
Expand All @@ -339,24 +339,24 @@ given_registered_domains(Config, DomainsList) ->
end.

register_static_domains(DomainsList) ->
ejabberd_config:add_global_option(hosts, DomainsList),
ejabberd_config:add_global_option(host_types, []),
ejabberd_config:add_local_option(hosts, DomainsList),
ejabberd_config:add_local_option(host_types, []),
mongoose_domain_api:stop(),
mongoose_domain_api:init().

register_dynamic_domains(DomainsList) ->
ejabberd_config:add_global_option(hosts, []),
ejabberd_config:add_global_option(host_types, [<<"test type">>, <<"empty type">>]),
ejabberd_config:add_local_option(hosts, []),
ejabberd_config:add_local_option(host_types, [<<"test type">>, <<"empty type">>]),
mongoose_domain_api:stop(),
mongoose_domain_api:init(),
[mongoose_domain_core:insert(Domain, <<"test type">>, test) || Domain <- DomainsList].

%% ACLs might be an empty list
set_host_rule(Rule, Host, ACLs) ->
ejabberd_config:add_global_option({access, Rule, Host}, ACLs),
ejabberd_config:add_local_option({access, Rule, Host}, ACLs),
ok.

%% ACLs might be an empty list
set_global_rule(Rule, ACLs) ->
ejabberd_config:add_global_option({access, Rule, global}, ACLs),
ejabberd_config:add_local_option({access, Rule, global}, ACLs),
ok.
30 changes: 11 additions & 19 deletions test/commands_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,6 @@ groups() ->
}
].

glo({auth_method, _}) ->
dummy;
glo(Any) ->
?PRT("what do you want", Any),
none.

ggo({access, experts_only, _}) ->
[{allow, coder}, {allow, manager}, {deny, all}];
ggo({access, _, _}) ->
[];
ggo({acl, coder, _}) ->
[{user, <<"zenek">>}];
ggo(Any) ->
?PRT("global what do you want", Any),
none.

init_per_suite(C) ->
application:ensure_all_started(jid),
ok = mnesia:start(),
Expand Down Expand Up @@ -87,9 +71,8 @@ stop_helper_proc(C) ->

init_per_testcase(_, C) ->
meck:new(ejabberd_config),
meck:expect(ejabberd_config, get_local_option, fun glo/1),
meck:expect(ejabberd_config, get_global_option, fun ggo/1),
meck:expect(ejabberd_config, get_global_option_or_default, fun(K, _) -> ggo(K) end),
meck:expect(ejabberd_config, get_local_option, fun get_opt/1),
meck:expect(ejabberd_config, get_local_option_or_default, fun(K, _) -> get_opt(K) end),
meck:new(ejabberd_auth_dummy, [non_strict]),
meck:expect(ejabberd_auth_dummy, get_password_s, fun(_, _) -> <<"">> end),
meck:new(mongoose_domain_api),
Expand All @@ -100,6 +83,15 @@ end_per_testcase(_, C) ->
meck:unload(),
C.

get_opt({auth_method, _}) ->
dummy;
get_opt({access, experts_only, _}) ->
[{allow, coder}, {allow, manager}, {deny, all}];
get_opt({access, _, _}) ->
[];
get_opt({acl, coder, _}) ->
[{user, <<"zenek">>}].

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% test methods
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down
11 changes: 4 additions & 7 deletions test/ejabberd_c2s_SUITE_mocks.erl
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ setup() ->
meck:new(ejabberd_config),
meck:expect(ejabberd_config, get_local_option,
fun default_local_option/1),
meck:expect(ejabberd_config, get_global_option,
fun default_global_option/1),
meck:expect(acl, match_rule_for_host_type, fun(_, _, _, _) -> allow end),

meck:new(mongoose_bin, [passthrough]),
Expand All @@ -61,11 +59,10 @@ setup() ->
teardown() ->
meck:unload().

default_local_option(max_fsm_queue) -> 100.

default_global_option(default_server_domain) -> <<"localhost">>;
default_global_option({access, c2s_shaper, _}) -> [];
default_global_option(language) -> <<"en">>.
default_local_option(max_fsm_queue) -> 100;
default_local_option(default_server_domain) -> <<"localhost">>;
default_local_option({access, c2s_shaper, _}) -> [];
default_local_option(language) -> <<"en">>.

mcred_get(dummy_creds, username) -> <<"cosmic_hippo">>;
mcred_get(dummy_creds, auth_module) -> auuuthmodule.
Expand Down
7 changes: 4 additions & 3 deletions test/ejabberd_sm_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -599,13 +599,14 @@ terminate_sm() ->
gen_server:stop(ejabberd_sm).

set_meck(SMBackend) ->
meck:expect(ejabberd_config, get_global_option, fun(sm_backend) -> SMBackend end),
meck:expect(ejabberd_config, get_global_option_or_default,
meck:expect(ejabberd_config, get_local_option, fun(sm_backend) -> SMBackend;
(_) -> undefined
end),
meck:expect(ejabberd_config, get_local_option_or_default,
fun
(hosts, _Default) -> [<<"localhost">>];
(host_types, Default) -> Default
end),
meck:expect(ejabberd_config, get_local_option, fun(_) -> undefined end),
meck:expect(gen_hook, add_handler, fun(_, _, _, _, _) -> ok end),

meck:new(ejabberd_commands, []),
Expand Down
2 changes: 1 addition & 1 deletion test/gen_mod_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ all() ->

init_per_testcase(_, Config) ->
meck:new(ejabberd_config, [passthrough]),
meck:expect(ejabberd_config, get_global_option_or_default,
meck:expect(ejabberd_config, get_local_option_or_default,
fun(hosts, _) -> [<<"localhost">>, <<"localhost.bis">>] end),
meck:expect(ejabberd_config, get_local_option, fun(_) -> undefined end),
meck:expect(ejabberd_config, add_local_option, fun(_, _) -> {atomic, ok} end),
Expand Down
2 changes: 1 addition & 1 deletion test/mod_global_distrib_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fake_acc_to_component(From) ->

set_meck() ->
meck:new(ejabberd_config, []),
meck:expect(ejabberd_config, get_global_option_or_default,
meck:expect(ejabberd_config, get_local_option_or_default,
fun(hosts, _) -> [global_host(), local_host()] end),
meck:expect(ejabberd_config, get_local_option, fun(_) -> undefined end),

Expand Down
5 changes: 2 additions & 3 deletions test/mongoose_cleanup_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,13 @@ setup_meck([ejabberd_local | R]) ->
setup_meck(R);
setup_meck([ejabberd_config | R]) ->
meck:new(ejabberd_config),
meck:expect(ejabberd_config, get_global_option_or_default,
meck:expect(ejabberd_config, get_local_option_or_default,
fun(_, Default) -> Default end),
meck:expect(ejabberd_config, get_global_option,
meck:expect(ejabberd_config, get_local_option,
fun
(hosts) -> [];
(_) -> undefined
end),
meck:expect(ejabberd_config, get_local_option, fun(_) -> undefined end),
setup_meck(R);
setup_meck([ejabberd_commands | R]) ->
meck:new(ejabberd_commands),
Expand Down
7 changes: 5 additions & 2 deletions test/mongoose_service_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ init_per_testcase(module_deps, C) ->
init_per_testcase(generic, C),
meck:expect(ejabberd_config, get_local_option, fun(_) -> undefined end),
meck:expect(ejabberd_config, add_local_option, fun(_, _) -> ok end),
meck:expect(ejabberd_config, get_global_option_or_default,
fun(hosts, _) -> [<<"localhost">>] end),
% This fun needs the second clause because it overwrites the previous mock
meck:expect(ejabberd_config, get_local_option_or_default,
fun(hosts, _) -> [<<"localhost">>];
(services, _) -> [{Serv, []} || Serv <- services()]
end),
gen_mod:start(),
meck:new(module_a, [non_strict]),
meck:expect(module_a, deps, fun(_, _) -> [{service, service_d}, {service, service_h}] end),
Expand Down
2 changes: 1 addition & 1 deletion test/mongoose_wpool_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ init_per_suite(Config) ->
ok = meck:new(wpool, [no_link, passthrough]),
ok = meck:new(mongoose_wpool, [no_link, passthrough]),
ok = meck:new(ejabberd_config, [no_link]),
meck:expect(ejabberd_config, get_global_option_or_default,
meck:expect(ejabberd_config, get_local_option_or_default,
fun(hosts, _) -> [<<"a.com">>, <<"b.com">>, <<"c.eu">>];
(host_types, _) -> [] end),
Self = self(),
Expand Down
11 changes: 5 additions & 6 deletions test/mongooseim_metrics_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,14 @@ wait_for_update({ok, [{count,0}]}, N) ->

setup_meck(Group) ->
meck:new(ejabberd_config, [no_link]),
meck:expect(ejabberd_config, get_global_option, fun(hosts) -> [<<"localhost">>] end),
meck:expect(ejabberd_config, get_global_option_or_default,
meck:expect(ejabberd_config, get_local_option,
fun(hosts) -> [<<"localhost">>];
(all_metrics_are_global) -> Group =:= all_metrics_are_global
end),
meck:expect(ejabberd_config, get_local_option_or_default,
fun (hosts, _Def) -> [<<"localhost">>];
(_, _) -> []
end),
meck:expect(ejabberd_config, get_local_option,
fun (all_metrics_are_global) -> Group =:= all_metrics_are_global;
(_) -> undefined
end),
ok.

get_reporters_cfg(Port) ->
Expand Down
2 changes: 1 addition & 1 deletion test/roster_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ init_per_suite(C) ->
meck:new(mongoose_domain_api, [no_link]),
meck:expect(mongoose_domain_api, get_domain_host_type, fun(_) -> {ok, host_type()} end),
meck:new(ejabberd_config, [no_link, passthrough]),
meck:expect(ejabberd_config, get_global_option_or_default,
meck:expect(ejabberd_config, get_local_option_or_default,
fun(hosts, Default) -> Default end),
C.

Expand Down
2 changes: 1 addition & 1 deletion test/translate_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,5 @@ given_loaded_translations() ->
given_default_language(Lang) ->
(catch meck:unload()),
meck:new(ejabberd_config),
meck:expect(ejabberd_config, get_global_option, fun(language) -> Lang end),
meck:expect(ejabberd_config, get_local_option, fun(language) -> Lang end),
ok.

0 comments on commit ce7f288

Please sign in to comment.