From 1ade88402c0682853af22f6e7aaef89f72d7f91b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chmielowski?= Date: Mon, 30 May 2016 23:05:45 +0200 Subject: [PATCH] Better code for setting up ejabberd app location --- test/elixir_SUITE.erl | 12 +----------- test/suite.erl | 27 +++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/test/elixir_SUITE.erl b/test/elixir_SUITE.erl index 835c81052..aaef9151d 100644 --- a/test/elixir_SUITE.erl +++ b/test/elixir_SUITE.erl @@ -18,17 +18,7 @@ -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. diff --git a/test/suite.erl b/test/suite.erl index bcd54bef3..d4722b81c 100644 --- a/test/suite.erl +++ b/test/suite.erl @@ -12,6 +12,7 @@ -compile(export_all). -include("suite.hrl"). +-include_lib("kernel/include/file.hrl"). %%%=================================================================== %%% API @@ -47,10 +48,7 @@ init_config(Config) -> ]), 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), @@ -74,6 +72,27 @@ init_config(Config) -> {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