feat: node array support array(atom()) and comma_separated_atoms

This commit is contained in:
某文 2023-04-09 21:35:46 +08:00 committed by Zhongwen Deng
parent 586cd54aa2
commit 933e6727ba
2 changed files with 45 additions and 2 deletions

View File

@ -135,7 +135,7 @@ fields("cluster") ->
)}, )},
{"core_nodes", {"core_nodes",
sc( sc(
emqx_schema:comma_separated_atoms(), node_array(),
#{ #{
mapping => "mria.core_nodes", mapping => "mria.core_nodes",
default => [], default => [],
@ -203,7 +203,7 @@ fields(cluster_static) ->
[ [
{"seeds", {"seeds",
sc( sc(
hoconsc:array(atom()), node_array(),
#{ #{
default => [], default => [],
desc => ?DESC(cluster_static_seeds), desc => ?DESC(cluster_static_seeds),
@ -1312,3 +1312,6 @@ validator_string_re(Val, RE, Error) ->
catch catch
_:_ -> {error, Error} _:_ -> {error, Error}
end. end.
node_array() ->
hoconsc:union([emqx_schema:comma_separated_atoms(), hoconsc:array(atom())]).

View File

@ -5,6 +5,46 @@
-module(emqx_conf_schema_tests). -module(emqx_conf_schema_tests).
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
array_nodes_test() ->
ExpectNodes = ['emqx1@127.0.0.1', 'emqx2@127.0.0.1'],
BaseConf =
""
"\n"
" node {\n"
" name = \"emqx1@127.0.0.1\"\n"
" cookie = \"emqxsecretcookie\"\n"
" data_dir = \"data\"\n"
" }\n"
" cluster {\n"
" name = emqxcl\n"
" discovery_strategy = static\n"
" static.seeds = ~p\n"
" core_nodes = ~p\n"
" }\n"
" "
"",
lists:foreach(
fun(Nodes) ->
ConfFile = iolist_to_binary(io_lib:format(BaseConf, [Nodes, Nodes])),
{ok, Conf} = hocon:binary(ConfFile, #{format => richmap}),
ConfList = hocon_tconf:generate(emqx_conf_schema, Conf),
ClusterDiscovery = proplists:get_value(
cluster_discovery, proplists:get_value(ekka, ConfList)
),
?assertEqual(
{static, [{seeds, ExpectNodes}]},
ClusterDiscovery,
Nodes
),
?assertEqual(
ExpectNodes,
proplists:get_value(core_nodes, proplists:get_value(mria, ConfList)),
Nodes
)
end,
[["emqx1@127.0.0.1", "emqx2@127.0.0.1"], "emqx1@127.0.0.1, emqx2@127.0.0.1"]
),
ok.
doc_gen_test() -> doc_gen_test() ->
%% the json file too large to encode. %% the json file too large to encode.