]> granicus.if.org Git - ejabberd/commitdiff
Better code for setting up ejabberd app location
authorPaweł Chmielowski <pchmielowski@process-one.net>
Mon, 30 May 2016 21:05:45 +0000 (23:05 +0200)
committerPaweł Chmielowski <pchmielowski@process-one.net>
Mon, 30 May 2016 21:06:29 +0000 (23:06 +0200)
test/elixir_SUITE.erl
test/suite.erl

index 835c81052ee23064e16d734320e17ec960cda255..aaef9151dd613e73af16886a21002d3fa87ea14a 100644 (file)
 -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.
index bcd54bef3e5087c32bafb25d35414e56418dc3a3..d4722b81c48d1777cd189e14288883b4a0f2aef7 100644 (file)
@@ -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