aboutsummaryrefslogtreecommitdiffstats
path: root/test/rlx_extended_bin_SUITE.erl
diff options
context:
space:
mode:
authorTristan Sloughter <[email protected]>2018-06-12 19:07:22 -0600
committerGitHub <[email protected]>2018-06-12 19:07:22 -0600
commitee477fb31ad9a7603aaea8922aaa9ecd3712ee2d (patch)
tree5d37580d953db02cddfbf1821d3ba535677e3e1e /test/rlx_extended_bin_SUITE.erl
parent53f4c6eb6b57408a8b3cad412373db534a13ca1f (diff)
downloadrelx-ee477fb31ad9a7603aaea8922aaa9ecd3712ee2d.tar.gz
relx-ee477fb31ad9a7603aaea8922aaa9ecd3712ee2d.tar.bz2
relx-ee477fb31ad9a7603aaea8922aaa9ecd3712ee2d.zip
support for OTP21's sys.config.src file in releases (#647)
* support for OTP21's sys.config.src file in releases * always replace os vars in .src files if found * support vm_args_src to be consistent with sys_config_src * add newlines after warning logs * improve sys and vm src config tests
Diffstat (limited to 'test/rlx_extended_bin_SUITE.erl')
-rw-r--r--test/rlx_extended_bin_SUITE.erl119
1 files changed, 118 insertions, 1 deletions
diff --git a/test/rlx_extended_bin_SUITE.erl b/test/rlx_extended_bin_SUITE.erl
index 9fd47c0..86a9d23 100644
--- a/test/rlx_extended_bin_SUITE.erl
+++ b/test/rlx_extended_bin_SUITE.erl
@@ -42,6 +42,7 @@
escript/1,
remote_console/1, shortname_remote_console/1,
replace_os_vars/1,
+ replace_os_vars_sys_config_vm_args_src/1,
replace_os_vars_multi_node/1,
replace_os_vars_included_config/1,
replace_os_vars_custom_location/1,
@@ -85,7 +86,8 @@ all() ->
start_fail_when_missing_argsfile, start_fail_when_nonreadable_argsfile,
start_fail_when_relative_argsfile, start_fail_when_circular_argsfiles,
ping, shortname_ping, longname_ping, attach, pid, restart, reboot, escript,
- remote_console, shortname_remote_console, replace_os_vars, replace_os_vars_multi_node, replace_os_vars_included_config,
+ remote_console, shortname_remote_console, replace_os_vars, replace_os_vars_sys_config_vm_args_src, replace_os_vars_multi_node,
+ replace_os_vars_included_config,
replace_os_vars_custom_location, replace_os_vars_dev_mode, replace_os_vars_twice, custom_start_script_hooks,
builtin_wait_for_vm_start_script_hook, builtin_pid_start_script_hook,
builtin_wait_for_process_start_script_hook, mixed_custom_and_builtin_start_script_hooks,
@@ -579,6 +581,121 @@ replace_os_vars(Config) ->
{"COOKIE", "cookie2"}]),
ok.
+
+replace_os_vars_sys_config_vm_args_src(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"]),
+ SysConfigSrc = filename:join([LibDir1, "sys.config.src"]),
+ VmArgs = filename:join([LibDir1, "vm.args.src"]),
+
+ rlx_test_utils:write_config(ConfigFile,
+ [{release, {foo, "0.0.1"},
+ [goal_app]},
+ {lib_dirs, [filename:join(LibDir1, "*")]},
+ {sys_config_src, SysConfigSrc},
+ {vm_args_src, VmArgs},
+ {generate_start_script, true},
+ {extended_start_script, true}
+ ]),
+
+ %% new with sys.config.src it doesn't have to be valid Erlang
+ %% until after var replacemen at runtime.
+ ec_file:write(SysConfigSrc, "[{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"},
+ {"NODENAME", "node1"},
+ {"COOKIE", "cookie1"},
+ {"VAR1", "101"}]),
+ timer:sleep(2000),
+ {ok, "pong"} = sh(filename:join([OutputDir, "foo", "bin", "foo ping"]),
+ [{"RELX_REPLACE_OS_VARS", "1"},
+ {"NODENAME", "node1"},
+ {"COOKIE", "cookie1"}]),
+ {ok, "101"} = sh(filename:join([OutputDir, "foo", "bin",
+ "foo eval '{ok, V} = application:get_env(goal_app, var1), V.'"]),
+ [{"RELX_REPLACE_OS_VARS", "1"},
+ {"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"},
+ {"NODENAME", "node1"},
+ {"COOKIE", "cookie1"}]),
+ {ok, "cookie1"} = sh(filename:join([OutputDir, "foo", "bin",
+ "foo eval 'erlang:get_cookie().'"]),
+ [{"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.config"]))),
+ {ok, _} = sh(filename:join([OutputDir, "foo", "bin", "foo stop"]),
+ [{"RELX_REPLACE_OS_VARS", "1"},
+ {"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"},
+ {"NODENAME", "node2"},
+ {"COOKIE", "cookie2"},
+ {"VAR1", "201"}]),
+ timer:sleep(2000),
+ {ok, "pong"} = sh(filename:join([OutputDir, "foo", "bin", "foo ping"]),
+ [{"RELX_REPLACE_OS_VARS", "1"},
+ {"NODENAME", "node2"},
+ {"COOKIE", "cookie2"}]),
+ {ok, "201"} = sh(filename:join([OutputDir, "foo", "bin",
+ "foo eval '{ok, V} = application:get_env(goal_app, var1), V.'"]),
+ [{"RELX_REPLACE_OS_VARS", "1"},
+ {"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"},
+ {"NODENAME", "node2"},
+ {"COOKIE", "cookie2"}]),
+ {ok, "cookie2"} = sh(filename:join([OutputDir, "foo", "bin",
+ "foo eval 'erlang:get_cookie().'"]),
+ [{"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.config"]))),
+ {ok, _} = sh(filename:join([OutputDir, "foo", "bin", "foo stop"]),
+ [{"RELX_REPLACE_OS_VARS", "1"},
+ {"NODENAME", "node2"},
+ {"COOKIE", "cookie2"}]),
+ ok.
+
replace_os_vars_multi_node(Config) ->
LibDir1 = proplists:get_value(lib1, Config),