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

Run tests only on backends enabled by configure

This commit is contained in:
Paweł Chmielowski 2018-01-30 15:16:52 +01:00
parent bb58307190
commit 3b646cc2ec
3 changed files with 47 additions and 11 deletions

View File

@ -271,6 +271,19 @@ if test "$sqlite" = "true"; then
fi fi
fi fi
enabled_backends=""
for backend in odbc mysql pgsql sqlite riak redis; do
if eval test x\${$backend} = xtrue; then
if test "x$enabled_backends" = "x"; then
enabled_backends=$backend
else
enabled_backends="$enabled_backends, $backend"
fi
fi
done
echo "EB: $enabled_backends"
AC_SUBST(hipe) AC_SUBST(hipe)
AC_SUBST(roster_gateway_workaround) AC_SUBST(roster_gateway_workaround)
AC_SUBST(new_sql_schema) AC_SUBST(new_sql_schema)
@ -295,5 +308,6 @@ AC_SUBST(system_deps)
AC_SUBST(CFLAGS) AC_SUBST(CFLAGS)
AC_SUBST(CPPFLAGS) AC_SUBST(CPPFLAGS)
AC_SUBST(LDFLAGS) AC_SUBST(LDFLAGS)
AC_SUBST(enabled_backends)
AC_OUTPUT AC_OUTPUT

View File

@ -6,7 +6,7 @@
{modules, []}, {modules, []},
{registered, []}, {registered, []},
{applications, [kernel, stdlib]}, {applications, [kernel, stdlib]},
{env, []}, {env, [{enabled_backends, [@enabled_backends@]}]},
{mod, {ejabberd_app, []}}]}. {mod, {ejabberd_app, []}}]}.

View File

@ -70,11 +70,14 @@ init_config(Config) ->
{pgsql_user, <<"ejabberd_test">>}, {pgsql_user, <<"ejabberd_test">>},
{pgsql_pass, <<"ejabberd_test">>} {pgsql_pass, <<"ejabberd_test">>}
]), ]),
Backends = get_config_backends(), HostTypes = re:split(CfgContent, "(\\s*- \"(.*)\\.localhost\")",
[group, {return, binary}]),
Types = [binary_to_list(Type) || [_, _, Type] <- HostTypes],
Backends = get_config_backends(Types),
HostTypes = re:split(CfgContent, "(\\s*- \"(.*)\\.localhost\")", HostTypes = re:split(CfgContent, "(\\s*- \"(.*)\\.localhost\")",
[group, {return, binary}]), [group, {return, binary}]),
CfgContent2 = lists:foldl(fun([Pre, Frag, Type], Acc) -> CfgContent2 = lists:foldl(fun([Pre, Frag, Type], Acc) ->
case Backends == all orelse lists:member(binary_to_list(Type), Backends) of case lists:member(binary_to_list(Type), Backends) of
true -> true ->
<<Acc/binary, Pre/binary, Frag/binary>>; <<Acc/binary, Pre/binary, Frag/binary>>;
_ -> _ ->
@ -88,7 +91,10 @@ init_config(Config) ->
setup_ejabberd_lib_path(Config), setup_ejabberd_lib_path(Config),
ok = application:load(sasl), ok = application:load(sasl),
ok = application:load(mnesia), ok = application:load(mnesia),
ok = application:load(ejabberd), case application:load(ejabberd) of
ok -> ok;
{error, {already_loaded, _}} -> ok
end,
application:set_env(ejabberd, config, ConfigPath), application:set_env(ejabberd, config, ConfigPath),
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}),
@ -151,13 +157,29 @@ setup_ejabberd_lib_path(Config) ->
%% Read environment variable CT_DB=riak,mysql to limit the backends to test. %% Read environment variable CT_DB=riak,mysql to limit the backends to test.
%% You can thus limit the backend you want to test with: %% You can thus limit the backend you want to test with:
%% CT_BACKENDS=riak,mysql rebar ct suites=ejabberd %% CT_BACKENDS=riak,mysql rebar ct suites=ejabberd
get_config_backends() -> get_config_backends(Types) ->
case os:getenv("CT_BACKENDS") of EnvBackends = case os:getenv("CT_BACKENDS") of
false -> all; false -> Types;
String -> String ->
Backends0 = string:tokens(String, ","), Backends0 = string:tokens(String, ","),
lists:map(fun(Backend) -> string:strip(Backend, both, $ ) end, Backends0) lists:map(fun(Backend) -> string:strip(Backend, both, $ ) end, Backends0)
end. end,
application:load(ejabberd),
EnabledBackends = lists:map(fun(V) when is_atom(V) ->
atom_to_list(V);
(V) ->
V
end,
application:get_env(ejabberd, enabled_backends, Types)),
lists:foldl(fun(Backend, Backends) ->
case lists:member(Backend, EnabledBackends) of
false ->
lists:delete(Backend, Backends);
_ ->
Backends
end
end, EnvBackends, ["odbc", "mysql", "pgsql",
"sqlite", "riak", "redis"]).
process_config_tpl(Content, []) -> process_config_tpl(Content, []) ->
Content; Content;