From be0fd6fddd58597935e1aa97280fa2edac4c93f6 Mon Sep 17 00:00:00 2001 From: DDDHuang <44492639+DDDHuang@users.noreply.github.com> Date: Fri, 3 Sep 2021 10:57:54 +0800 Subject: [PATCH] fix: add sub api doc & test suite (#5634) * fix: add sub api doc & test suite --- .../src/emqx_mgmt_api_subscriptions.erl | 4 ++-- .../test/emqx_mgmt_subscription_api_SUITE.erl | 21 ++++++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/apps/emqx_management/src/emqx_mgmt_api_subscriptions.erl b/apps/emqx_management/src/emqx_mgmt_api_subscriptions.erl index 5c2475e95..3afd52050 100644 --- a/apps/emqx_management/src/emqx_mgmt_api_subscriptions.erl +++ b/apps/emqx_management/src/emqx_mgmt_api_subscriptions.erl @@ -96,13 +96,13 @@ parameters() -> #{ name => topic, in => query, - description => <<"Topic">>, + description => <<"Topic, url encoding">>, schema => #{type => string} } #{ name => match_topic, in => query, - description => <<"Match topic string">>, + description => <<"Match topic string, url encoding">>, schema => #{type => string} } | page_params() ]. diff --git a/apps/emqx_management/test/emqx_mgmt_subscription_api_SUITE.erl b/apps/emqx_management/test/emqx_mgmt_subscription_api_SUITE.erl index f2d8c6eb2..b344bcd11 100644 --- a/apps/emqx_management/test/emqx_mgmt_subscription_api_SUITE.erl +++ b/apps/emqx_management/test/emqx_mgmt_subscription_api_SUITE.erl @@ -24,8 +24,10 @@ -define(USERNAME, <<"api_username">>). %% notice: integer topic for sort response --define(TOPIC1, <<"0000">>). --define(TOPIC2, <<"0001">>). +-define(TOPIC1, <<"/t/0000">>). +-define(TOPIC2, <<"/t/0001">>). + +-define(TOPIC_SORT, #{?TOPIC1 => 1, ?TOPIC2 => 2}). all() -> emqx_ct:all(?MODULE). @@ -53,11 +55,24 @@ t_subscription_api(_) -> ?assertEqual(length(Subscriptions), 2), Sort = fun(#{<<"topic">> := T1}, #{<<"topic">> := T2}) -> - binary_to_integer(T1) =< binary_to_integer(T2) + maps:get(T1, ?TOPIC_SORT) =< maps:get(T2, ?TOPIC_SORT) end, [Subscriptions1, Subscriptions2] = lists:sort(Sort, Subscriptions), ?assertEqual(maps:get(<<"topic">>, Subscriptions1), ?TOPIC1), ?assertEqual(maps:get(<<"topic">>, Subscriptions2), ?TOPIC2), ?assertEqual(maps:get(<<"clientid">>, Subscriptions1), ?CLIENTID), ?assertEqual(maps:get(<<"clientid">>, Subscriptions2), ?CLIENTID), + + QsTopic = "topic=" ++ <<"%2Ft%2F0001">>, + 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), + + emqtt:disconnect(Client).