test(emqx_mgmt): test list_nodes/0
This commit is contained in:
parent
777ca72ad5
commit
fc33bce40d
|
@ -22,6 +22,8 @@
|
||||||
|
|
||||||
-export([
|
-export([
|
||||||
all/1,
|
all/1,
|
||||||
|
init_per_testcase/3,
|
||||||
|
end_per_testcase/3,
|
||||||
boot_modules/1,
|
boot_modules/1,
|
||||||
start_apps/1,
|
start_apps/1,
|
||||||
start_apps/2,
|
start_apps/2,
|
||||||
|
@ -150,6 +152,19 @@ all(Suite) ->
|
||||||
string:substr(atom_to_list(F), 1, 2) == "t_"
|
string:substr(atom_to_list(F), 1, 2) == "t_"
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
init_per_testcase(Module, TestCase, Config) ->
|
||||||
|
case erlang:function_exported(Module, TestCase, 2) of
|
||||||
|
true -> Module:TestCase(init, Config);
|
||||||
|
false -> Config
|
||||||
|
end.
|
||||||
|
|
||||||
|
end_per_testcase(Module, TestCase, Config) ->
|
||||||
|
case erlang:function_exported(Module, TestCase, 2) of
|
||||||
|
true -> Module:TestCase('end', Config);
|
||||||
|
false -> ok
|
||||||
|
end,
|
||||||
|
Config.
|
||||||
|
|
||||||
%% set emqx app boot modules
|
%% set emqx app boot modules
|
||||||
-spec boot_modules(all | list(atom())) -> ok.
|
-spec boot_modules(all | list(atom())) -> ok.
|
||||||
boot_modules(Mods) ->
|
boot_modules(Mods) ->
|
||||||
|
|
|
@ -158,7 +158,7 @@ node_info(Nodes) ->
|
||||||
emqx_rpc:unwrap_erpc(emqx_management_proto_v3:node_info(Nodes)).
|
emqx_rpc:unwrap_erpc(emqx_management_proto_v3:node_info(Nodes)).
|
||||||
|
|
||||||
stopped_node_info(Node) ->
|
stopped_node_info(Node) ->
|
||||||
#{name => Node, node_status => 'stopped'}.
|
{Node, #{node => Node, node_status => 'stopped'}}.
|
||||||
|
|
||||||
vm_stats() ->
|
vm_stats() ->
|
||||||
Idle =
|
Idle =
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
%% Copyright (c) 2022-2023 EMQ Technologies Co., Ltd. All Rights Reserved.
|
||||||
|
%%
|
||||||
|
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
%% you may not use this file except in compliance with the License.
|
||||||
|
%% You may obtain a copy of the License at
|
||||||
|
%%
|
||||||
|
%% http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
%%
|
||||||
|
%% Unless required by applicable law or agreed to in writing, software
|
||||||
|
%% distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
%% See the License for the specific language governing permissions and
|
||||||
|
%% limitations under the License.
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
-module(emqx_mgmt_SUITE).
|
||||||
|
|
||||||
|
-compile(export_all).
|
||||||
|
-compile(nowarn_export_all).
|
||||||
|
|
||||||
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
|
||||||
|
all() ->
|
||||||
|
emqx_common_test_helpers:all(?MODULE).
|
||||||
|
|
||||||
|
init_per_suite(Config) ->
|
||||||
|
emqx_mgmt_api_test_util:init_suite([emqx_conf, emqx_management]),
|
||||||
|
Config.
|
||||||
|
|
||||||
|
end_per_suite(_) ->
|
||||||
|
emqx_mgmt_api_test_util:end_suite([emqx_management, emqx_conf]).
|
||||||
|
|
||||||
|
init_per_testcase(TestCase, Config) ->
|
||||||
|
emqx_common_test_helpers:init_per_testcase(?MODULE, TestCase, Config).
|
||||||
|
|
||||||
|
end_per_testcase(TestCase, Config) ->
|
||||||
|
emqx_common_test_helpers:end_per_testcase(?MODULE, TestCase, Config).
|
||||||
|
|
||||||
|
t_list_nodes(init, Config) ->
|
||||||
|
meck:expect(
|
||||||
|
mria_mnesia,
|
||||||
|
cluster_nodes,
|
||||||
|
fun
|
||||||
|
(running) -> [node()];
|
||||||
|
(stopped) -> ['stopped@node']
|
||||||
|
end
|
||||||
|
),
|
||||||
|
Config;
|
||||||
|
t_list_nodes('end', _Config) ->
|
||||||
|
meck:unload(mria_mnesia).
|
||||||
|
|
||||||
|
t_list_nodes(_) ->
|
||||||
|
NodeInfos = emqx_mgmt:list_nodes(),
|
||||||
|
Node = node(),
|
||||||
|
?assertMatch(
|
||||||
|
[
|
||||||
|
{Node, #{node := Node, node_status := 'running'}},
|
||||||
|
{'stopped@node', #{node := 'stopped@node', node_status := 'stopped'}}
|
||||||
|
],
|
||||||
|
NodeInfos
|
||||||
|
).
|
Loading…
Reference in New Issue