-compile(export_all).
init_per_suite(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 = filename:dirname(filename:dirname(filename:dirname(DataDir))),
- ok = file:make_symlink(TopDir, NewEjPath),
- code:replace_path(ejabberd, NewEjPath);
- _ ->
- ok
- end,
+ suite:setup_ejabberd_lib_path(Config),
check_meck(),
code:add_pathz(filename:join(test_dir(), "../include")),
Config.
-compile(export_all).
-include("suite.hrl").
+-include_lib("kernel/include/file.hrl").
%%%===================================================================
%%% API
]),
ConfigPath = filename:join([CWD, "ejabberd.yml"]),
ok = file:write_file(ConfigPath, CfgContent),
- NewEjPath = filename:join([CWD, "ejabberd-0.0.1"]),
- TopDir = filename:dirname(filename:dirname(DataDir)),
- ok = file:make_symlink(TopDir, NewEjPath),
- code:replace_path(ejabberd, NewEjPath),
+ setup_ejabberd_lib_path(Config),
ok = application:load(sasl),
ok = application:load(mnesia),
ok = application:load(ejabberd),
{backends, get_config_backends()}
|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.
%% You can thus limit the backend you want to test with:
%% CT_BACKENDS=riak,mysql rebar ct suites=ejabberd