Skip to content

Commit

Permalink
Hardcode test options
Browse files Browse the repository at this point in the history
  • Loading branch information
arcusfelis committed Mar 9, 2022
1 parent f884434 commit e24caa4
Show file tree
Hide file tree
Showing 8 changed files with 302 additions and 302 deletions.
2 changes: 1 addition & 1 deletion big_tests/tests/muc_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ init_per_group(_GroupName, Config) ->

required_modules(http_auth) ->
MucHostPattern = ct:get_config({hosts, mim, muc_service_pattern}),
DefRoomOpts = rpc(mim(), mod_muc, default_room_opts, []),
DefRoomOpts = config_parser_helper:default_room_opts(),
Opts = #{host => subhost_pattern(MucHostPattern),
access => muc,
access_create => muc_create,
Expand Down
6 changes: 2 additions & 4 deletions big_tests/tests/muc_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@

%% Extend default opts with new ExtraOpts
make_opts(ExtraOpts) ->
Opts = rpc(mim(), mod_muc, default_opts, []),
maps:merge(Opts, ExtraOpts).
config_parser_helper:mod_config(mod_muc, ExtraOpts).

make_log_opts(ExtraOpts) ->
Opts = rpc(mim(), mod_muc_log, default_opts, []),
maps:merge(Opts, ExtraOpts).
config_parser_helper:mod_config(mod_muc_log, ExtraOpts).

-spec foreach_occupant(
Users :: [escalus:client()], Stanza :: #xmlel{}, VerifyFun :: verify_fun()) -> ok.
Expand Down
4 changes: 0 additions & 4 deletions src/config/mongoose_config_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
-module(mongoose_config_utils).
-export([exit_or_halt/1]).
-export([section_to_defaults/1]).
-export([keys_are_binaries/1]).
-ignore_xref([section_to_defaults/1]).

-include("mongoose_config_spec.hrl").
Expand All @@ -22,6 +21,3 @@ exit_or_halt(ExitText) ->

section_to_defaults(#section{defaults = Defaults}) ->
Defaults.

keys_are_binaries(KV) ->
maps:from_list([{atom_to_binary(K, latin1), V} || {K, V} <- maps:to_list(KV)]).
8 changes: 1 addition & 7 deletions src/inbox/mod_inbox.erl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ process_entry(#{remote_jid := RemJID,
-spec deps(jid:lserver(), list()) -> gen_mod_deps:deps().
deps(_Host, Opts) ->
Groupchats = gen_mod:get_opt(groupchat, Opts),
muclight_dep(Groupchats) ++ muc_dep(Groupchats).
muclight_dep(Groupchats).

-spec start(mongooseim:host_type(), gen_mod:module_opts()) -> ok.
start(HostType, #{iqdisc := IQDisc, groupchat := MucTypes} = Opts) ->
Expand Down Expand Up @@ -553,12 +553,6 @@ muclight_dep(List) ->
false -> []
end.

muc_dep(List) ->
case lists:member(muc, List) of
true -> [{mod_muc, mod_muc:default_opts(), hard}];
false -> []
end.

-spec muclight_enabled(HostType :: mongooseim:host_type()) -> boolean().
muclight_enabled(HostType) ->
Groupchats = get_groupchat_types(HostType),
Expand Down
115 changes: 55 additions & 60 deletions src/mod_muc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,11 @@
-export([hibernated_rooms_number/0]).

-export([config_metrics/1]).
-export([default_opts/0]).
-export([default_room_opts/0]).

-ignore_xref([
can_access_identity/4, can_access_room/4, acc_room_affiliations/2, create_instant_room/6,
disco_local_items/1, hibernated_rooms_number/0, is_muc_room_owner/4, remove_domain/3,
online_rooms_number/0, register_room/4, restore_room/3, start_link/2,
default_room_opts/0
]).
online_rooms_number/0, register_room/4, restore_room/3, start_link/2]).

-include("mongoose.hrl").
-include("jlib.hrl").
Expand Down Expand Up @@ -251,36 +247,37 @@ config_spec() ->
validate = non_negative},
<<"default_room">> => default_room_config_spec()
},
defaults = mongoose_config_utils:keys_are_binaries(default_opts())
defaults = defaults()
}.

default_opts() ->
#{
backend => mnesia,
host => default_host(),
access => all,
access_create => all,
access_admin => none,
access_persistent => all,
history_size => 20,
room_shaper => none,
max_room_id => infinity,
max_room_name => infinity,
max_room_desc => infinity,
min_message_interval => 0,
min_presence_interval => 0,
max_users => ?MAX_USERS_DEFAULT,
max_users_admin_threshold => 5,
user_message_shaper => none,
user_presence_shaper => none,
max_user_conferences => 10,
http_auth_pool => none,
load_permanent_rooms_at_startup => false,
hibernate_timeout => timer:seconds(90),
hibernated_room_check_interval => infinity,
hibernated_room_timeout => infinity,
default_room => default_room_opts()
}.
defaults() ->
#{<<"backend">> => mnesia,
<<"host">> => default_host(),
<<"access">> => all,
<<"access_create">> => all,
<<"access_admin">> => none,
<<"access_persistent">> => all,
<<"history_size">> => 20,
<<"room_shaper">> => none,
<<"max_room_id">> => infinity,
<<"max_room_name">> => infinity,
<<"max_room_desc">> => infinity,
<<"min_message_interval">> => 0,
<<"min_presence_interval">> => 0,
<<"max_users">> => ?MAX_USERS_DEFAULT,
<<"max_users_admin_threshold">> => 5,
<<"user_message_shaper">> => none,
<<"user_presence_shaper">> => none,
<<"max_user_conferences">> => 10,
<<"http_auth_pool">> => none,
<<"load_permanent_rooms_at_startup">> => false,
<<"hibernate_timeout">> => timer:seconds(90),
<<"hibernated_room_check_interval">> => infinity,
<<"hibernated_room_timeout">> => infinity,
<<"default_room">> => keys_as_atoms(default_room_opts())}.

keys_as_atoms(Map) ->
maps:from_list([{binary_to_atom(K), V} || {K, V} <- maps:to_list(Map)]).

default_room_config_spec() ->
#section{
Expand Down Expand Up @@ -312,37 +309,35 @@ default_room_config_spec() ->
<<"subject">> => #option{type = binary},
<<"subject_author">> => #option{type = binary}
},
defaults = mongoose_config_utils:keys_are_binaries(default_room_opts())
defaults = default_room_opts()
}.

default_room_opts() ->
X = #config{},
#{
title => X#config.title,
description => X#config.description,
allow_change_subj => X#config.allow_change_subj,
allow_query_users => X#config.allow_query_users,
allow_private_messages => X#config.allow_private_messages,
allow_visitor_status => X#config.allow_visitor_status,
allow_visitor_nickchange => X#config.allow_visitor_nickchange,
public => X#config.public,
public_list => X#config.public_list,
persistent => X#config.persistent,
moderated => X#config.moderated,
members_by_default => X#config.members_by_default,
members_only => X#config.members_only,
allow_user_invites => X#config.allow_user_invites,
allow_multiple_sessions => X#config.allow_multiple_sessions,
password_protected => X#config.password_protected,
password => X#config.password,
anonymous => X#config.anonymous,
max_users => X#config.max_users,
logging => X#config.logging,
maygetmemberlist => X#config.maygetmemberlist,
affiliations => [],
subject => <<>>,
subject_author => <<>>
}.
#{<<"title">> => X#config.title,
<<"description">> => X#config.description,
<<"allow_change_subj">> => X#config.allow_change_subj,
<<"allow_query_users">> => X#config.allow_query_users,
<<"allow_private_messages">> => X#config.allow_private_messages,
<<"allow_visitor_status">> => X#config.allow_visitor_status,
<<"allow_visitor_nickchange">> => X#config.allow_visitor_nickchange,
<<"public">> => X#config.public,
<<"public_list">> => X#config.public_list,
<<"persistent">> => X#config.persistent,
<<"moderated">> => X#config.moderated,
<<"members_by_default">> => X#config.members_by_default,
<<"members_only">> => X#config.members_only,
<<"allow_user_invites">> => X#config.allow_user_invites,
<<"allow_multiple_sessions">> => X#config.allow_multiple_sessions,
<<"password_protected">> => X#config.password_protected,
<<"password">> => X#config.password,
<<"anonymous">> => X#config.anonymous,
<<"max_users">> => X#config.max_users,
<<"logging">> => X#config.logging,
<<"maygetmemberlist">> => X#config.maygetmemberlist,
<<"affiliations">> => [],
<<"subject">> => <<>>,
<<"subject_author">> => <<>>}.

default_room_affiliations_spec() ->
#section{
Expand Down
27 changes: 11 additions & 16 deletions src/mod_muc_log.erl
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,11 @@
-export([config_spec/0,
process_top_link/1]).

-export([default_opts/0]).

%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).

-ignore_xref([start_link/2]).
-ignore_xref([default_opts/0]).

-include("mongoose.hrl").
-include("jlib.hrl").
Expand Down Expand Up @@ -150,21 +147,19 @@ config_spec() ->
<<"top_link">> => top_link_config_spec(),
<<"spam_prevention">> => #option{type = boolean}
},
defaults = mongoose_config_utils:keys_are_binaries(default_opts())
defaults = defaults()
}.

default_opts() ->
#{
outdir => "www/muc",
access_log => muc_admin,
dirtype => subdirs,
dirname => room_jid,
file_format => html,
css_file => false,
timezone => local,
top_link => {"/", "Home"},
spam_prevention => true
}.
defaults() ->
#{<<"outdir">> => "www/muc",
<<"access_log">> => muc_admin,
<<"dirtype">> => subdirs,
<<"dirname">> => room_jid,
<<"file_format">> => html,
<<"css_file">> => false,
<<"timezone">> => local,
<<"top_link">> => {"/", "Home"},
<<"spam_prevention">> => true}.

top_link_config_spec() ->
#section{
Expand Down
94 changes: 77 additions & 17 deletions test/common/config_parser_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -532,11 +532,11 @@ all_modules() ->
#{host => <<"192.168.0.1">>, type => turn}]},
mod_csi => [{buffer_max, 40}],
mod_muc_log =>
(mod_muc_log:default_opts())
#{access_log => muc,
css_file => <<"path/to/css/file">>,
outdir => "www/muc",
top_link => {"/", "Home"}},
mod_config(mod_muc_log,
#{access_log => muc,
css_file => <<"path/to/css/file">>,
outdir => "www/muc",
top_link => {"/", "Home"}}),
mod_http_upload =>
[{backend, s3},
{expiration_time, 120},
Expand Down Expand Up @@ -627,17 +627,16 @@ all_modules() ->
#{backend => mnesia, inactivity => 20, max_wait => infinity,
server_acks => true, max_pause => 120},
mod_muc =>
(mod_muc:default_opts())
#{access => muc,
access_create => muc_create,
default_room =>
(mod_muc:default_room_opts())
#{affiliations =>
[{{<<"alice">>, <<"localhost">>, <<"resource1">>}, member},
{{<<"bob">>, <<"localhost">>, <<"resource2">>}, owner}],
password_protected => true},
host => {fqdn, <<"muc.example.com">>},
http_auth_pool => my_auth_pool},
mod_config(mod_muc,
#{access => muc,
access_create => muc_create,
default_room => (default_room_opts())
#{affiliations =>
[{{<<"alice">>, <<"localhost">>, <<"resource1">>}, member},
{{<<"bob">>, <<"localhost">>, <<"resource2">>}, owner}],
password_protected => true},
host => {fqdn, <<"muc.example.com">>},
http_auth_pool => my_auth_pool}),
mod_vcard =>
mod_config(mod_vcard,
#{host => {fqdn, <<"directory.example.com">>},
Expand Down Expand Up @@ -893,7 +892,68 @@ default_mod_config(mod_mam_rdbms_arch) ->
default_mod_config(mod_mam_muc_rdbms_arch) ->
#{no_writer => false,
db_message_format => mam_message_compressed_eterm,
db_jid_format => mam_jid_rfc}.
db_jid_format => mam_jid_rfc};
default_mod_config(mod_muc) ->
#{backend => mnesia,
host => {prefix,<<"conference.">>},
access => all,
access_create => all,
access_admin => none,
access_persistent => all,
history_size => 20,
room_shaper => none,
max_room_id => infinity,
max_room_name => infinity,
max_room_desc => infinity,
min_message_interval => 0,
min_presence_interval => 0,
max_users => 200,
max_users_admin_threshold => 5,
user_message_shaper => none,
user_presence_shaper => none,
max_user_conferences => 10,
http_auth_pool => none,
load_permanent_rooms_at_startup => false,
hibernate_timeout => timer:seconds(90),
hibernated_room_check_interval => infinity,
hibernated_room_timeout => infinity,
default_room => default_room_opts()};
default_mod_config(mod_muc_log) ->
#{outdir => "www/muc",
access_log => muc_admin,
dirtype => subdirs,
dirname => room_jid,
file_format => html,
css_file => false,
timezone => local,
top_link => {"/", "Home"},
spam_prevention => true}.

default_room_opts() ->
#{title => <<>>,
description => <<>>,
allow_change_subj => true,
allow_query_users => true,
allow_private_messages => true,
allow_visitor_status => true,
allow_visitor_nickchange => true,
public => true,
public_list => true,
persistent => false,
moderated => true,
members_by_default => true,
members_only => false,
allow_user_invites => false,
allow_multiple_sessions => false,
password_protected => false,
password => <<>>,
anonymous => true,
max_users => 200,
logging => false,
maygetmemberlist => [],
affiliations => [],
subject => <<>>,
subject_author => <<>>}.

default_config([modules, M]) ->
default_mod_config(M);
Expand Down
Loading

0 comments on commit e24caa4

Please sign in to comment.