aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLuis Rascão <[email protected]>2016-11-11 16:46:48 +0000
committerGitHub <[email protected]>2016-11-11 16:46:48 +0000
commitc305c89713abf48570e2db152b367f00ac641893 (patch)
tree5ff0e6c569051730571e49e5620f5419b31dd5d8 /test
parentf74972a6e65fc4c2a1ba098b4cea230a4b7a63f2 (diff)
parent103af5c657fa38e44f04c93702d0e55a3271d82b (diff)
downloadrelx-c305c89713abf48570e2db152b367f00ac641893.tar.gz
relx-c305c89713abf48570e2db152b367f00ac641893.tar.bz2
relx-c305c89713abf48570e2db152b367f00ac641893.zip
Merge pull request #427 from saleyn/vars
Remove name collisions of replaced files in multi-node setups
Diffstat (limited to 'test')
-rw-r--r--test/rlx_extended_bin_SUITE.erl186
-rw-r--r--test/rlx_test_utils.erl4
2 files changed, 189 insertions, 1 deletions
diff --git a/test/rlx_extended_bin_SUITE.erl b/test/rlx_extended_bin_SUITE.erl
index 9a15bf8..2bd0554 100644
--- a/test/rlx_extended_bin_SUITE.erl
+++ b/test/rlx_extended_bin_SUITE.erl
@@ -30,6 +30,7 @@
escript/1,
remote_console/1,
replace_os_vars/1,
+ replace_os_vars_custom_location/1,
replace_os_vars_dev_mode/1,
replace_os_vars_twice/1]).
@@ -57,7 +58,9 @@ init_per_testcase(_, Config) ->
all() ->
[ping, attach, pid, restart, reboot, escript,
- remote_console, replace_os_vars, replace_os_vars_dev_mode].
+ remote_console,
+ replace_os_vars, replace_os_vars_custom_location,
+ replace_os_vars_dev_mode, replace_os_vars_twice].
ping(Config) ->
LibDir1 = proplists:get_value(lib1, Config),
@@ -370,6 +373,16 @@ replace_os_vars(Config) ->
[{"RELX_REPLACE_OS_VARS", "1"},
{"NODENAME", "node1"},
{"COOKIE", "cookie1"}]),
+ {ok, Node1} = sh(filename:join([OutputDir, "foo", "bin",
+ "foo eval 'atom_to_list(node()).'"]),
+ [{"RELX_REPLACE_OS_VARS", "1"},
+ {"NODENAME", "node1"},
+ {"COOKIE", "cookie1"}]),
+ %% check that the replaced files have been created in the right place
+ ?assert(ec_file:exists(filename:join([OutputDir, "foo", "releases", "0.0.1",
+ "sys." ++
+ rlx_test_utils:unescape_string(Node1) ++
+ ".config"]))),
{ok, _} = sh(filename:join([OutputDir, "foo", "bin", "foo stop"]),
[{"RELX_REPLACE_OS_VARS", "1"},
{"NODENAME", "node1"},
@@ -401,12 +414,153 @@ replace_os_vars(Config) ->
[{"RELX_REPLACE_OS_VARS", "1"},
{"NODENAME", "node2"},
{"COOKIE", "cookie2"}]),
+ {ok, Node2} = sh(filename:join([OutputDir, "foo", "bin",
+ "foo eval 'atom_to_list(node()).'"]),
+ [{"RELX_REPLACE_OS_VARS", "1"},
+ {"NODENAME", "node2"},
+ {"COOKIE", "cookie2"}]),
+ %% check that the replaced files have been created in the right place
+ ?assert(ec_file:exists(filename:join([OutputDir, "foo", "releases", "0.0.1",
+ "sys." ++
+ rlx_test_utils:unescape_string(Node2) ++
+ ".config"]))),
{ok, _} = sh(filename:join([OutputDir, "foo", "bin", "foo stop"]),
[{"RELX_REPLACE_OS_VARS", "1"},
{"NODENAME", "node2"},
{"COOKIE", "cookie2"}]),
ok.
+replace_os_vars_custom_location(Config) ->
+ LibDir1 = proplists:get_value(lib1, Config),
+
+ rlx_test_utils:create_app(LibDir1, "goal_app", "0.0.1", [stdlib,kernel], []),
+
+ ConfigFile = filename:join([LibDir1, "relx.config"]),
+ SysConfig = filename:join([LibDir1, "sys.config"]),
+ VmArgs = filename:join([LibDir1, "vm.args"]),
+
+ rlx_test_utils:write_config(ConfigFile,
+ [{release, {foo, "0.0.1"},
+ [goal_app]},
+ {lib_dirs, [filename:join(LibDir1, "*")]},
+ {sys_config, SysConfig},
+ {vm_args, VmArgs},
+ {generate_start_script, true},
+ {extended_start_script, true}
+ ]),
+
+ rlx_test_utils:write_config(SysConfig,
+ [[{goal_app, [{var1, "${VAR1}"}]}]]),
+ ec_file:write(VmArgs, "-sname ${NODENAME}\n\n"
+ "-setcookie ${COOKIE}\n"),
+
+ OutputDir = filename:join([proplists:get_value(priv_dir, Config),
+ rlx_test_utils:create_random_name("relx-output")]),
+
+ {ok, _State} = relx:do([{relname, foo},
+ {relvsn, "0.0.1"},
+ {goals, []},
+ {lib_dirs, [LibDir1]},
+ {log_level, 3},
+ {output_dir, OutputDir},
+ {config, ConfigFile}], ["release"]),
+
+ {ok, _} = sh(filename:join([OutputDir, "foo", "bin", "foo start"]),
+ [{"RELX_REPLACE_OS_VARS", "1"},
+ {"RELX_OUT_FILE_PATH", "/tmp"},
+ {"NODENAME", "node1"},
+ {"COOKIE", "cookie1"},
+ {"VAR1", "v1"}]),
+ timer:sleep(2000),
+ {ok, "pong"} = sh(filename:join([OutputDir, "foo", "bin", "foo ping"]),
+ [{"RELX_REPLACE_OS_VARS", "1"},
+ {"RELX_OUT_FILE_PATH", "/tmp"},
+ {"NODENAME", "node1"},
+ {"COOKIE", "cookie1"}]),
+ {ok, "\"v1\""} = sh(filename:join([OutputDir, "foo", "bin",
+ "foo eval '{ok, V} = application:get_env(goal_app, var1), V.'"]),
+ [{"RELX_REPLACE_OS_VARS", "1"},
+ {"RELX_OUT_FILE_PATH", "/tmp"},
+ {"NODENAME", "node1"},
+ {"COOKIE", "cookie1"}]),
+ {ok, "\"node1\""} = sh(filename:join([OutputDir, "foo", "bin",
+ "foo eval '[Node,_] = re:split(atom_to_list(node()), \"@\"),binary_to_list(Node).'"]),
+ [{"RELX_REPLACE_OS_VARS", "1"},
+ {"RELX_OUT_FILE_PATH", "/tmp"},
+ {"NODENAME", "node1"},
+ {"COOKIE", "cookie1"}]),
+ {ok, "cookie1"} = sh(filename:join([OutputDir, "foo", "bin",
+ "foo eval 'erlang:get_cookie().'"]),
+ [{"RELX_REPLACE_OS_VARS", "1"},
+ {"RELX_OUT_FILE_PATH", "/tmp"},
+ {"NODENAME", "node1"},
+ {"COOKIE", "cookie1"}]),
+ {ok, Node1} = sh(filename:join([OutputDir, "foo", "bin",
+ "foo eval 'atom_to_list(node()).'"]),
+ [{"RELX_REPLACE_OS_VARS", "1"},
+ {"RELX_OUT_FILE_PATH", "/tmp"},
+ {"NODENAME", "node1"},
+ {"COOKIE", "cookie1"}]),
+ %% check that the replaced files have been created in the right place
+ ?assert(ec_file:exists(filename:join(["/", "tmp",
+ "sys." ++
+ rlx_test_utils:unescape_string(Node1) ++
+ ".config"]))),
+ {ok, _} = sh(filename:join([OutputDir, "foo", "bin", "foo stop"]),
+ [{"RELX_REPLACE_OS_VARS", "1"},
+ {"RELX_OUT_FILE_PATH", "/tmp"},
+ {"NODENAME", "node1"},
+ {"COOKIE", "cookie1"}]),
+
+ %% start the node again but this time with different env variables to replace
+ {ok, _} = sh(filename:join([OutputDir, "foo", "bin", "foo start"]),
+ [{"RELX_REPLACE_OS_VARS", "1"},
+ {"RELX_OUT_FILE_PATH", "/tmp"},
+ {"NODENAME", "node2"},
+ {"COOKIE", "cookie2"},
+ {"VAR1", "v2"}]),
+ timer:sleep(2000),
+ {ok, "pong"} = sh(filename:join([OutputDir, "foo", "bin", "foo ping"]),
+ [{"RELX_REPLACE_OS_VARS", "1"},
+ {"RELX_OUT_FILE_PATH", "/tmp"},
+ {"NODENAME", "node2"},
+ {"COOKIE", "cookie2"}]),
+ {ok, "\"v2\""} = sh(filename:join([OutputDir, "foo", "bin",
+ "foo eval '{ok, V} = application:get_env(goal_app, var1), V.'"]),
+ [{"RELX_REPLACE_OS_VARS", "1"},
+ {"RELX_OUT_FILE_PATH", "/tmp"},
+ {"NODENAME", "node2"},
+ {"COOKIE", "cookie2"}]),
+ {ok, "\"node2\""} = sh(filename:join([OutputDir, "foo", "bin",
+ "foo eval '[Node,_] = re:split(atom_to_list(node()), \"@\"),binary_to_list(Node).'"]),
+ [{"RELX_REPLACE_OS_VARS", "1"},
+ {"RELX_OUT_FILE_PATH", "/tmp"},
+ {"NODENAME", "node2"},
+ {"COOKIE", "cookie2"}]),
+ {ok, "cookie2"} = sh(filename:join([OutputDir, "foo", "bin",
+ "foo eval 'erlang:get_cookie().'"]),
+ [{"RELX_REPLACE_OS_VARS", "1"},
+ {"RELX_OUT_FILE_PATH", "/tmp"},
+ {"NODENAME", "node2"},
+ {"COOKIE", "cookie2"}]),
+ {ok, Node2} = sh(filename:join([OutputDir, "foo", "bin",
+ "foo eval 'atom_to_list(node()).'"]),
+ [{"RELX_REPLACE_OS_VARS", "1"},
+ {"RELX_OUT_FILE_PATH", "/tmp"},
+ {"NODENAME", "node2"},
+ {"COOKIE", "cookie2"}]),
+ %% check that the replaced files have been created in the right place
+ ?assert(ec_file:exists(filename:join(["/", "tmp",
+ "sys." ++
+ rlx_test_utils:unescape_string(Node2) ++
+ ".config"]))),
+ {ok, _} = sh(filename:join([OutputDir, "foo", "bin", "foo stop"]),
+ [{"RELX_REPLACE_OS_VARS", "1"},
+ {"RELX_OUT_FILE_PATH", "/tmp"},
+ {"NODENAME", "node2"},
+ {"COOKIE", "cookie2"}]),
+ ok.
+
replace_os_vars_twice(Config) ->
LibDir1 = proplists:get_value(lib1, Config),
@@ -457,6 +611,16 @@ replace_os_vars_twice(Config) ->
{ok, "cookie"} = sh(filename:join([OutputDir, "foo", "bin",
"foo eval 'erlang:get_cookie().'"]),
[{"RELX_REPLACE_OS_VARS", "1"}]),
+ {ok, Node1} = sh(filename:join([OutputDir, "foo", "bin",
+ "foo eval 'atom_to_list(node()).'"]),
+ [{"RELX_REPLACE_OS_VARS", "1"},
+ {"NODENAME", "node1"},
+ {"COOKIE", "cookie1"}]),
+ %% check that the replaced files have been created in the right place
+ ?assert(ec_file:exists(filename:join([OutputDir, "foo", "releases", "0.0.1",
+ "sys." ++
+ rlx_test_utils:unescape_string(Node1) ++
+ ".config"]))),
{ok, _} = sh(filename:join([OutputDir, "foo", "bin", "foo stop"]),
[{"RELX_REPLACE_OS_VARS", "1"}]),
@@ -534,6 +698,16 @@ replace_os_vars_dev_mode(Config) ->
[{"RELX_REPLACE_OS_VARS", "1"},
{"NODENAME", "node1"},
{"COOKIE", "cookie1"}]),
+ {ok, Node1} = sh(filename:join([OutputDir, "foo", "bin",
+ "foo eval 'atom_to_list(node()).'"]),
+ [{"RELX_REPLACE_OS_VARS", "1"},
+ {"NODENAME", "node1"},
+ {"COOKIE", "cookie1"}]),
+ %% check that the replaced files have been created in the right place
+ ?assert(ec_file:exists(filename:join([OutputDir, "foo", "releases", "0.0.1",
+ "sys." ++
+ rlx_test_utils:unescape_string(Node1) ++
+ ".config"]))),
{ok, _} = sh(filename:join([OutputDir, "foo", "bin", "foo stop"]),
[{"RELX_REPLACE_OS_VARS", "1"},
{"NODENAME", "node1"},
@@ -565,6 +739,16 @@ replace_os_vars_dev_mode(Config) ->
[{"RELX_REPLACE_OS_VARS", "1"},
{"NODENAME", "node2"},
{"COOKIE", "cookie2"}]),
+ {ok, Node2} = sh(filename:join([OutputDir, "foo", "bin",
+ "foo eval 'atom_to_list(node()).'"]),
+ [{"RELX_REPLACE_OS_VARS", "1"},
+ {"NODENAME", "node2"},
+ {"COOKIE", "cookie2"}]),
+ %% check that the replaced files have been created in the right place
+ ?assert(ec_file:exists(filename:join([OutputDir, "foo", "releases", "0.0.1",
+ "sys." ++
+ rlx_test_utils:unescape_string(Node2) ++
+ ".config"]))),
{ok, _} = sh(filename:join([OutputDir, "foo", "bin", "foo stop"]),
[{"RELX_REPLACE_OS_VARS", "1"},
{"NODENAME", "node2"},
diff --git a/test/rlx_test_utils.erl b/test/rlx_test_utils.erl
index b6f6d7e..3ddc134 100644
--- a/test/rlx_test_utils.erl
+++ b/test/rlx_test_utils.erl
@@ -110,3 +110,7 @@ list_to_term(String) ->
{error, Error} ->
Error
end.
+
+unescape_string(String) ->
+ re:replace(String, "\"", "",
+ [global, {return, list}]). \ No newline at end of file