test: cover the node params for `get /configs` endpoint

This commit is contained in:
JianBo He 2023-07-19 08:51:26 +08:00 committed by zhongwencool
parent 74532a64e6
commit 439eb4d029
1 changed files with 25 additions and 14 deletions

View File

@ -272,18 +272,22 @@ t_dashboard(_Config) ->
t_configs_node({'init', Config}) -> t_configs_node({'init', Config}) ->
Node = node(), Node = node(),
meck:expect(emqx, running_nodes, fun() -> [Node, bad_node, other_node] end), meck:expect(emqx, running_nodes, fun() -> [Node, bad_node, other_node] end),
meck:expect( F = fun
emqx_management_proto_v4, (Node0) when Node0 =:= Node -> <<"\"self\"">>;
get_full_config, (other_node) -> <<"\"other\"">>;
fun (bad_node) -> {badrpc, bad}
(Node0) when Node0 =:= Node -> <<"\"self\"">>; end,
(other_node) -> <<"\"other\"">>; F2 = fun
(bad_node) -> {badrpc, bad} (Node0, _) when Node0 =:= Node -> <<"log=1">>;
end (other_node, _) -> <<"log=2">>;
), (bad_node, _) -> {badrpc, bad}
end,
meck:expect(emqx_management_proto_v4, get_full_config, F),
meck:expect(emqx_conf_proto_v3, get_hocon_config, F2),
meck:expect(hocon_pp, do, fun(Conf, _) -> Conf end),
Config; Config;
t_configs_node({'end', _}) -> t_configs_node({'end', _}) ->
meck:unload([emqx, emqx_management_proto_v4]); meck:unload([emqx, emqx_management_proto_v4, emqx_conf_proto_v3, hocon_pp]);
t_configs_node(_) -> t_configs_node(_) ->
Node = atom_to_list(node()), Node = atom_to_list(node()),
@ -296,7 +300,10 @@ t_configs_node(_) ->
{_, _, Body} = ExpRes, {_, _, Body} = ExpRes,
?assertMatch(#{<<"code">> := <<"NOT_FOUND">>}, emqx_utils_json:decode(Body, [return_maps])), ?assertMatch(#{<<"code">> := <<"NOT_FOUND">>}, emqx_utils_json:decode(Body, [return_maps])),
?assertMatch({error, {_, 500, _}}, get_configs_with_json("bad_node")). ?assertMatch({error, {_, 500, _}}, get_configs_with_json("bad_node")),
?assertEqual({ok, #{<<"log">> => 1}}, get_configs_with_binary("log", Node)),
?assertEqual({ok, #{<<"log">> => 2}}, get_configs_with_binary("log", "other_node")).
%% v2 version binary %% v2 version binary
t_configs_key(_Config) -> t_configs_key(_Config) ->
@ -386,12 +393,16 @@ get_configs_with_json(Node, Opts) ->
end. end.
get_configs_with_binary(Key) -> get_configs_with_binary(Key) ->
get_configs_with_binary(Key, node()).
get_configs_with_binary(Key, Node) ->
Path0 = "configs?node=" ++ Node,
Path = Path =
case Key of case Key of
undefined -> ["configs"]; undefined -> Path0;
_ -> ["configs?key=" ++ Key] _ -> Path0 ++ "&key=" ++ Key
end, end,
URI = emqx_mgmt_api_test_util:api_path(Path), URI = emqx_mgmt_api_test_util:api_path([Path]),
Auth = emqx_mgmt_api_test_util:auth_header_(), Auth = emqx_mgmt_api_test_util:auth_header_(),
Headers = [{"accept", "text/plain"}, Auth], Headers = [{"accept", "text/plain"}, Auth],
case emqx_mgmt_api_test_util:request_api(get, URI, [], Headers, [], #{return_all => true}) of case emqx_mgmt_api_test_util:request_api(get, URI, [], Headers, [], #{return_all => true}) of