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

Better code for setting up ejabberd app location

This commit is contained in:
Paweł Chmielowski 2016-05-30 23:05:45 +02:00
parent f252b9d489
commit 1ade88402c
2 changed files with 24 additions and 15 deletions

View File

@ -18,17 +18,7 @@
-compile(export_all). -compile(export_all).
init_per_suite(Config) -> init_per_suite(Config) ->
case code:lib_dir(ejabberd) of suite:setup_ejabberd_lib_path(Config),
{error, _} ->
DataDir = proplists:get_value(data_dir, Config),
{ok, CWD} = file:get_cwd(),
NewEjPath = filename:join([CWD, "ejabberd-0.0.1"]),
TopDir = filename:dirname(filename:dirname(filename:dirname(DataDir))),
ok = file:make_symlink(TopDir, NewEjPath),
code:replace_path(ejabberd, NewEjPath);
_ ->
ok
end,
check_meck(), check_meck(),
code:add_pathz(filename:join(test_dir(), "../include")), code:add_pathz(filename:join(test_dir(), "../include")),
Config. Config.

View File

@ -12,6 +12,7 @@
-compile(export_all). -compile(export_all).
-include("suite.hrl"). -include("suite.hrl").
-include_lib("kernel/include/file.hrl").
%%%=================================================================== %%%===================================================================
%%% API %%% API
@ -47,10 +48,7 @@ init_config(Config) ->
]), ]),
ConfigPath = filename:join([CWD, "ejabberd.yml"]), ConfigPath = filename:join([CWD, "ejabberd.yml"]),
ok = file:write_file(ConfigPath, CfgContent), ok = file:write_file(ConfigPath, CfgContent),
NewEjPath = filename:join([CWD, "ejabberd-0.0.1"]), setup_ejabberd_lib_path(Config),
TopDir = filename:dirname(filename:dirname(DataDir)),
ok = file:make_symlink(TopDir, NewEjPath),
code:replace_path(ejabberd, NewEjPath),
ok = application:load(sasl), ok = application:load(sasl),
ok = application:load(mnesia), ok = application:load(mnesia),
ok = application:load(ejabberd), ok = application:load(ejabberd),
@ -74,6 +72,27 @@ init_config(Config) ->
{backends, get_config_backends()} {backends, get_config_backends()}
|Config]. |Config].
find_top_dir(Dir) ->
case file:read_file_info(filename:join([Dir, ebin])) of
{ok, #file_info{type = directory}} ->
Dir;
_ ->
find_top_dir(filename:dirname(Dir))
end.
setup_ejabberd_lib_path(Config) ->
case code:lib_dir(ejabberd) of
{error, _} ->
DataDir = proplists:get_value(data_dir, Config),
{ok, CWD} = file:get_cwd(),
NewEjPath = filename:join([CWD, "ejabberd-0.0.1"]),
TopDir = find_top_dir(DataDir),
ok = file:make_symlink(TopDir, NewEjPath),
code:replace_path(ejabberd, NewEjPath);
_ ->
ok
end.
%% 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