Skip to content

Commit

Permalink
Merge pull request #747 from arcusfelis/template-redefined-variable
Browse files Browse the repository at this point in the history
Correctly render redefined variable
  • Loading branch information
tsloughter committed Aug 13, 2019
2 parents 912f513 + e644d7c commit def78e1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/rlx_prv_overlay.erl
Expand Up @@ -187,9 +187,11 @@ merge_overlay_vars(State, FileNames) ->
%% to the current one being read
OverlayRelativeRoot = filename:dirname(FileName),
NewTerms = check_overlay_inclusion(State, OverlayRelativeRoot, Terms),
%% Remove already defined variables from Acc,
%% append NewTerms, preserving order
lists:foldl(fun(NewTerm, A) ->
lists:keystore(element(1, NewTerm), 1, A, NewTerm)
end, Acc, NewTerms);
lists:keydelete(element(1, NewTerm), 1, A)
end, Acc, NewTerms) ++ NewTerms;
{error, Reason} ->
ec_cmd_log:warn(rlx_state:log(State),
format_error({unable_to_read_varsfile, FileName, Reason})),
Expand Down
12 changes: 10 additions & 2 deletions test/rlx_release_SUITE.erl
Expand Up @@ -818,14 +818,18 @@ overlay_release(Config) ->
goal_app_2]}]),

VarsFile1 = filename:join([LibDir1, "vars1.config"]),
%% tpl_var is defined in vars1, but redifined in vars2 using template.
rlx_test_utils:write_config(VarsFile1, [{yahoo, "yahoo"},
{yahoo2, [{foo, "bar"}]},
{foo_yahoo, "foo_{{yahoo}}"},
{foo_dir, "foodir"}]),
{foo_dir, "foodir"},
{tpl_var, "defined in vars1"}]),

VarsFile2 = filename:join([LibDir1, "vars2.config"]),
rlx_test_utils:write_config(VarsFile2, [{google, "yahoo"},
{yahoo2, "foo"},
{tpl_arg, "a template value"},
{tpl_var, "Redefined in vars2 with {{tpl_arg}}"},
OverlayVars3]),

VarsFile3 = filename:join([LibDir1, "vars3.config"]),
Expand Down Expand Up @@ -894,7 +898,11 @@ overlay_release(Config) ->
?assertEqual("val1",
proplists:get_value(prop1, TemplateData)),
?assertEqual(2,
proplists:get_value(prop2, TemplateData)).
proplists:get_value(prop2, TemplateData)),
%% This should be rendered correctly based on VarsFile2 file, regardless
%% of tpl_var defined in VarsFile1 or not.
?assertEqual("Redefined in vars2 with a template value",
proplists:get_value(tpl_var, TemplateData)).

make_goalless_release(Config) ->
LibDir1 = proplists:get_value(lib1, Config),
Expand Down
3 changes: 2 additions & 1 deletion test/rlx_test_utils.erl
Expand Up @@ -185,7 +185,8 @@ test_template_contents() ->
"{foo_yahoo, \"{{foo_yahoo}}\"}.\n"
"{google, \"{{google}}\"}.\n"
"{prop1, \"{{prop1}}\"}.\n"
"{prop2, {{prop2}}}.\n".
"{prop2, {{prop2}}}.\n"
"{tpl_var, \"{{tpl_var}}\"}.\n".

escript_contents() ->
"#!/usr/bin/env escript\n"
Expand Down

0 comments on commit def78e1

Please sign in to comment.