Skip to content

Commit

Permalink
fix: do not dump array content in CLI env override logs
Browse files Browse the repository at this point in the history
  • Loading branch information
zmstone committed Jul 3, 2024
1 parent 76171b8 commit 878fee7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
8 changes: 7 additions & 1 deletion src/hocon_cli.erl
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,13 @@ log_env_override(Var, Path, Value) ->
case Value of
V when is_binary(V) -> V;
V when is_map(V) -> "{...}";
V -> io_lib:format("~0p", [V])
V when is_list(V) ->
case length(V) of
0 -> "[]";
_ -> "[...]"
end;
V ->
io_lib:format("~0p", [V])
end,
?STDOUT("~s [~s]: ~s", [Var, Path, ValueStr]).

Expand Down
39 changes: 28 additions & 11 deletions test/hocon_cli_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,32 @@ now_time_test() ->
end).

generate_with_env_logging_test() ->
Envs = [
{"ZZZ_FOO", "{min: 1, max: 2}"},
{"ZZZ_FOO__MIN", "42"},
{"ZZZ_FOO__MAX", "43"},
{"ZZZ_FOO__NUMBERS", "[1,2]"},
{"HOCON_ENV_OVERRIDE_PREFIX", "ZZZ_"}
],
Expects = [
<<"ZZZ_FOO [foo]: {...}">>,
<<"ZZZ_FOO__MAX [foo.max]: 43">>,
<<"ZZZ_FOO__MIN [foo.min]: 42">>,
<<"ZZZ_FOO__NUMBERS [foo.numbers]: [...]">>
],
test_generate_with_env_logging(Envs, Expects).

generate_with_env_logging_empty_array_test() ->
Envs = [
{"ZZZ_FOO__NUMBERS", "[]"},
{"HOCON_ENV_OVERRIDE_PREFIX", "ZZZ_"}
],
Expects = [
<<"ZZZ_FOO__NUMBERS [foo.numbers]: []">>
],
test_generate_with_env_logging(Envs, Expects).

test_generate_with_env_logging(Envs, Expects) ->
?CAPTURING(begin
Time = now_time(),
with_envs(
Expand All @@ -139,20 +165,11 @@ generate_with_env_logging_test() ->
"generate"
]
],
[
{"ZZZ_FOO", "{min: 1, max: 2}"},
{"ZZZ_FOO__MIN", "42"},
{"ZZZ_FOO__MAX", "43"},
{"HOCON_ENV_OVERRIDE_PREFIX", "ZZZ_"}
]
Envs
),
{ok, Stdout} = cuttlefish_test_group_leader:get_output(),
?assertEqual(
[
<<"ZZZ_FOO [foo]: {...}">>,
<<"ZZZ_FOO__MAX [foo.max]: 43">>,
<<"ZZZ_FOO__MIN [foo.min]: 42">>
],
Expects,
lists:sort(
binary:split(
iolist_to_binary(Stdout),
Expand Down

0 comments on commit 878fee7

Please sign in to comment.