Merge pull request #7154 from DDDHuang/tc_status
fix(test): add status api test suite
This commit is contained in:
commit
9bd55b0340
|
@ -53,12 +53,18 @@ schema("/status") ->
|
|||
%%--------------------------------------------------------------------
|
||||
|
||||
running_status(get, _Params) ->
|
||||
{InternalStatus, _ProvidedStatus} = init:get_status(),
|
||||
BrokerStatus =
|
||||
case emqx:is_running() of
|
||||
true ->
|
||||
started;
|
||||
false ->
|
||||
stopped
|
||||
end,
|
||||
AppStatus =
|
||||
case lists:keysearch(emqx, 1, application:which_applications()) of
|
||||
false -> not_running;
|
||||
{value, _Val} -> running
|
||||
end,
|
||||
Status = io_lib:format("Node ~ts is ~ts~nemqx is ~ts", [node(), InternalStatus, AppStatus]),
|
||||
Status = io_lib:format("Node ~ts is ~ts~nemqx is ~ts", [node(), BrokerStatus, AppStatus]),
|
||||
Body = list_to_binary(Status),
|
||||
{200, #{<<"content-type">> => <<"text/plain">>}, Body}.
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
%%--------------------------------------------------------------------
|
||||
%% Copyright (c) 2020-2022 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_api_status_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(),
|
||||
Config.
|
||||
|
||||
end_per_suite(_) ->
|
||||
emqx_mgmt_api_test_util:end_suite().
|
||||
|
||||
t_status(_Config) ->
|
||||
Path = emqx_mgmt_api_test_util:api_path(["status"]),
|
||||
Status = io_lib:format("Node ~ts is ~ts~nemqx is ~ts", [node(), started, running]),
|
||||
{ok, Status} = emqx_mgmt_api_test_util:request_api(get, Path),
|
||||
ok.
|
|
@ -24,8 +24,9 @@
|
|||
-define(USERNAME, <<"api_username">>).
|
||||
|
||||
%% notice: integer topic for sort response
|
||||
-define(TOPIC1, <<"/t/0000">>).
|
||||
-define(TOPIC2, <<"/t/0001">>).
|
||||
-define(TOPIC1, <<"t/0000">>).
|
||||
-define(TOPIC2, <<"$share/test_group/t/0001">>).
|
||||
-define(TOPIC2_TOPIC_ONLY, <<"t/0001">>).
|
||||
|
||||
-define(TOPIC_SORT, #{?TOPIC1 => 1, ?TOPIC2 => 2}).
|
||||
|
||||
|
@ -63,16 +64,22 @@ t_subscription_api(_) ->
|
|||
?assertEqual(maps:get(<<"clientid">>, Subscriptions1), ?CLIENTID),
|
||||
?assertEqual(maps:get(<<"clientid">>, Subscriptions2), ?CLIENTID),
|
||||
|
||||
QsTopic = "topic=" ++ <<"%2Ft%2F0001">>,
|
||||
QS = uri_string:compose_query([
|
||||
{"clientid", ?CLIENTID},
|
||||
{"topic", ?TOPIC2_TOPIC_ONLY},
|
||||
{"node", atom_to_list(node())},
|
||||
{"qos", "0"},
|
||||
{"share_group", "test_group"},
|
||||
{"match_topic", "t/#"}
|
||||
]),
|
||||
Headers = emqx_mgmt_api_test_util:auth_header_(),
|
||||
{ok, ResponseTopic1} = emqx_mgmt_api_test_util:request_api(get, Path, QsTopic, Headers),
|
||||
DataTopic1 = emqx_json:decode(ResponseTopic1, [return_maps]),
|
||||
Meta1 = maps:get(<<"meta">>, DataTopic1),
|
||||
?assertEqual(1, maps:get(<<"page">>, Meta1)),
|
||||
?assertEqual(emqx_mgmt:max_row_limit(), maps:get(<<"limit">>, Meta1)),
|
||||
?assertEqual(1, maps:get(<<"count">>, Meta1)),
|
||||
Subscriptions_qs1 = maps:get(<<"data">>, DataTopic1),
|
||||
?assertEqual(length(Subscriptions_qs1), 1),
|
||||
|
||||
{ok, ResponseTopic2} = emqx_mgmt_api_test_util:request_api(get, Path, QS, Headers),
|
||||
DataTopic2 = emqx_json:decode(ResponseTopic2, [return_maps]),
|
||||
Meta2 = maps:get(<<"meta">>, DataTopic2),
|
||||
?assertEqual(1, maps:get(<<"page">>, Meta2)),
|
||||
?assertEqual(emqx_mgmt:max_row_limit(), maps:get(<<"limit">>, Meta2)),
|
||||
?assertEqual(1, maps:get(<<"count">>, Meta2)),
|
||||
SubscriptionsList2 = maps:get(<<"data">>, DataTopic2),
|
||||
?assertEqual(length(SubscriptionsList2), 1),
|
||||
|
||||
emqtt:disconnect(Client).
|
||||
|
|
Loading…
Reference in New Issue