25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-22 17:28:25 +01:00

Add ability to configure parameters used by "make test" with test/config.ctc

This commit is contained in:
Paweł Chmielowski 2015-04-09 17:14:30 +02:00
parent e8701802ee
commit b9fdcc3985
3 changed files with 57 additions and 16 deletions

View File

@ -164,12 +164,21 @@ ElixirConfig = case lists:keysearch(elixir, 1, Cfg) of
{ok, Cwd} = file:get_cwd(), {ok, Cwd} = file:get_cwd(),
TestConfigFile = filename:join([Cwd, "test", "config.ctc"]),
TestConfig = case file:read_file_info(TestConfigFile) of
{ok, _} ->
"-userconfig ct_config_plain " ++ TestConfigFile ++ " ";
_ ->
""
end,
Config = [{erl_opts, Macros ++ HiPE ++ DebugInfo ++ Config = [{erl_opts, Macros ++ HiPE ++ DebugInfo ++
[{src_dirs, [asn1, src | SrcDirs]}]}, [{src_dirs, [asn1, src | SrcDirs]}]},
{sub_dirs, ["rel"]}, {sub_dirs, ["rel"]},
{keep_build_info, true}, {keep_build_info, true},
{ct_extra_params, "-include " {ct_extra_params, "-ct_hooks cth_surefire "
++ filename:join([Cwd, "tools"])}, ++ TestConfig
++ "-include " ++ filename:join([Cwd, "tools"])},
{xref_warnings, false}, {xref_warnings, false},
{xref_checks, []}, {xref_checks, []},
{xref_queries, {xref_queries,

View File

@ -1,12 +1,12 @@
host_config: host_config:
"pgsql.localhost": "pgsql.localhost":
odbc_username: "ejabberd_test" odbc_username: "@@pgsql_user@@"
odbc_type: pgsql odbc_type: pgsql
odbc_server: "localhost" odbc_server: "@@pgsql_server@@"
odbc_port: 5432 odbc_port: @@pgsql_port@@
odbc_pool_size: 1 odbc_pool_size: 1
odbc_password: "ejabberd_test" odbc_password: "@@pgsql_pass@@"
odbc_database: "ejabberd_test" odbc_database: "@@pgsql_db@@"
auth_method: odbc auth_method: odbc
modules: modules:
mod_announce: mod_announce:
@ -106,13 +106,13 @@ Welcome to this XMPP server."
mod_time: [] mod_time: []
mod_version: [] mod_version: []
"mysql.localhost": "mysql.localhost":
odbc_username: "ejabberd_test" odbc_username: "@@mysql_user@@"
odbc_type: mysql odbc_type: mysql
odbc_server: "localhost" odbc_server: "@@mysql_server@@"
odbc_port: 3306 odbc_port: @@mysql_port@@
odbc_pool_size: 1 odbc_pool_size: 1
odbc_password: "ejabberd_test" odbc_password: "@@mysql_pass@@"
odbc_database: "ejabberd_test" odbc_database: "@@mysql_db@@"
auth_method: odbc auth_method: odbc
modules: modules:
mod_announce: mod_announce:
@ -331,7 +331,7 @@ define_macro:
language: "en" language: "en"
listen: listen:
- -
port: 5222 port: @@c2s_port@@
module: ejabberd_c2s module: ejabberd_c2s
max_stanza_size: 65536 max_stanza_size: 65536
certfile: CERTFILE certfile: CERTFILE
@ -343,7 +343,7 @@ listen:
port: 5269 port: 5269
module: ejabberd_s2s_in module: ejabberd_s2s_in
- -
port: 5280 port: @@web_port@@
module: ejabberd_http module: ejabberd_http
captcha: true captcha: true
loglevel: 4 loglevel: 4

View File

@ -21,13 +21,30 @@ init_config(Config) ->
PrivDir = proplists:get_value(priv_dir, Config), PrivDir = proplists:get_value(priv_dir, Config),
[_, _|Tail] = lists:reverse(filename:split(DataDir)), [_, _|Tail] = lists:reverse(filename:split(DataDir)),
BaseDir = filename:join(lists:reverse(Tail)), BaseDir = filename:join(lists:reverse(Tail)),
ConfigPath = filename:join([DataDir, "ejabberd.yml"]), ConfigPathTpl = filename:join([DataDir, "ejabberd.yml"]),
LogPath = filename:join([PrivDir, "ejabberd.log"]), LogPath = filename:join([PrivDir, "ejabberd.log"]),
SASLPath = filename:join([PrivDir, "sasl.log"]), SASLPath = filename:join([PrivDir, "sasl.log"]),
MnesiaDir = filename:join([PrivDir, "mnesia"]), MnesiaDir = filename:join([PrivDir, "mnesia"]),
CertFile = filename:join([DataDir, "cert.pem"]), CertFile = filename:join([DataDir, "cert.pem"]),
{ok, CWD} = file:get_cwd(), {ok, CWD} = file:get_cwd(),
{ok, _} = file:copy(CertFile, filename:join([CWD, "cert.pem"])), {ok, _} = file:copy(CertFile, filename:join([CWD, "cert.pem"])),
{ok, CfgContentTpl} = file:read_file(ConfigPathTpl),
CfgContent = process_config_tpl(CfgContentTpl, [
{c2s_port, 5222},
{web_port, 5280},
{mysql_server, <<"localhost">>},
{mysql_port, 3306},
{mysql_db, <<"ejabberd_test">>},
{mysql_user, <<"ejabberd_test">>},
{mysql_pass, <<"ejabberd_test">>},
{pgsql_server, <<"localhost">>},
{pgsql_port, 5432},
{pgsql_db, <<"ejabberd_test">>},
{pgsql_user, <<"ejabberd_test">>},
{pgsql_pass, <<"ejabberd_test">>}
]),
ConfigPath = filename:join([CWD, "ejabberd.yml"]),
ok = file:write_file(ConfigPath, CfgContent),
ok = application:load(sasl), ok = application:load(sasl),
ok = application:load(mnesia), ok = application:load(mnesia),
ok = application:load(ejabberd), ok = application:load(ejabberd),
@ -35,7 +52,7 @@ init_config(Config) ->
application:set_env(ejabberd, log_path, LogPath), application:set_env(ejabberd, log_path, LogPath),
application:set_env(sasl, sasl_error_logger, {file, SASLPath}), application:set_env(sasl, sasl_error_logger, {file, SASLPath}),
application:set_env(mnesia, dir, MnesiaDir), application:set_env(mnesia, dir, MnesiaDir),
[{server_port, 5222}, [{server_port, ct:get_config(c2s_port, 5222)},
{server_host, "localhost"}, {server_host, "localhost"},
{server, ?COMMON_VHOST}, {server, ?COMMON_VHOST},
{user, <<"test_single">>}, {user, <<"test_single">>},
@ -50,6 +67,21 @@ init_config(Config) ->
{password, <<"password">>} {password, <<"password">>}
|Config]. |Config].
process_config_tpl(Content, []) ->
Content;
process_config_tpl(Content, [{Name, DefaultValue} | Rest]) ->
Val = case ct:get_config(Name, DefaultValue) of
V1 when is_integer(V1) ->
integer_to_binary(V1);
V2 when is_atom(V2) ->
atom_to_binary(V2, latin1);
V3 ->
V3
end,
NewContent = binary:replace(Content, <<"@@",(atom_to_binary(Name, latin1))/binary, "@@">>, Val),
process_config_tpl(NewContent, Rest).
connect(Config) -> connect(Config) ->
{ok, Sock} = ejabberd_socket:connect( {ok, Sock} = ejabberd_socket:connect(
?config(server_host, Config), ?config(server_host, Config),