Skip to content

Commit

Permalink
test: add richmap test
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongwencool committed May 3, 2023
1 parent 8167dd2 commit a470865
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions test/hocon_schema_aliases_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ check_root_test() ->
<<"root2">> => #{<<"key2">> => 2, <<"key3">> => "foo"}
},
hocon_tconf:check_plain(?MODULE, Conf)
),
{ok, RichConf} = hocon:binary(ConfText, #{format => richmap}),
?assertEqual(
#{
<<"old_root1">> => #{<<"key1">> => 1},
<<"root1">> => #{<<"key1">> => 1},
<<"root2">> => #{<<"key2">> => 2, <<"key3">> => "foo"}
},
hocon_util:richmap_to_map(hocon_tconf:check(?MODULE, RichConf))
).

check_converter_test() ->
Expand All @@ -76,6 +85,20 @@ check_converter_test() ->
<<"root2">> => #{<<"key2">> => 2, <<"key3">> => "foo", <<"key4">> => 4}
},
hocon_tconf:check_plain(?MODULE, Conf)
),
{ok, RichConf} = hocon:binary(ConfText, #{format => richmap}),
?assertEqual(
#{
<<"old_root1">> => #{<<"key1">> => 1},
<<"root1">> => #{<<"key1">> => 1},
<<"root2">> => #{
<<"key2">> => 2,
<<"key3">> => "foo",
<<"old_key4">> => 3,
<<"key4">> => 4
}
},
hocon_util:richmap_to_map(hocon_tconf:check(?MODULE, RichConf))
).

check_field_test() ->
Expand All @@ -89,6 +112,18 @@ check_field_test() ->
<<"root2">> => #{<<"key2">> => 2, <<"key3">> => "foo"}
},
hocon_tconf:check_plain(?MODULE, Conf)
),
{ok, RichConf} = hocon:binary(ConfText, #{format => richmap}),
?assertEqual(
#{
<<"old_root1">> => #{<<"key1">> => 1},
<<"root1">> => #{<<"key1">> => 1},
<<"root2">> => #{<<"key2">> => 2, <<"key3">> => "foo", <<"old_key2">> => 2}
%% deprecated field(old_root3,root3) is not included in the map
%%<<"old_root3">> => a,
%% <<"root3">> => b
},
hocon_util:richmap_to_map(hocon_tconf:check(?MODULE, RichConf))
).

check_env_test() ->
Expand All @@ -103,6 +138,22 @@ check_env_test() ->
<<"root2">> => #{<<"key2">> => 43, <<"key3">> => "foo", <<"key4">> => 2}
},
hocon_tconf:check_plain(?MODULE, Conf)
),
{ok, RichConf} = hocon:binary(ConfText, #{format => richmap}),
Conf1 = hocon_tconf:merge_env_overrides(?MODULE, RichConf, all, #{format => richmap}),
?assertEqual(
#{
<<"root1">> => #{<<"key1">> => 42},
<<"old_root1">> => #{<<"key1">> => 42},
<<"root2">> => #{
<<"key2">> => 43,
<<"old_key2">> => 43,
<<"key3">> => "foo",
<<"key4">> => 2,
<<"old_key4">> => 1
}
},
hocon_util:richmap_to_map(hocon_tconf:check(?MODULE, Conf1))
)
end,
with_envs(
Expand All @@ -127,6 +178,20 @@ check_mix_env_test() ->
<<"root2">> => #{<<"key2">> => 42, <<"key3">> => "foo"}
},
hocon_tconf:check_plain(?MODULE, Conf)
),
{ok, RichConf} = hocon:binary(ConfText, #{format => richmap}),
Conf1 = hocon_tconf:merge_env_overrides(?MODULE, RichConf, all, #{format => richmap}),
?assertEqual(
#{
<<"root1">> => #{<<"key1">> => 0, <<"key2">> => 2},
<<"old_root1">> => #{<<"key1">> => 0, <<"key2">> => 1},
<<"root2">> => #{
<<"key2">> => 42,
<<"old_key2">> => 42,
<<"key3">> => "foo"
}
},
hocon_util:richmap_to_map(hocon_tconf:check(?MODULE, Conf1))
)
end,
with_envs(
Expand Down

0 comments on commit a470865

Please sign in to comment.