fix(test): ifdb test SUITE & version compatibility
This commit is contained in:
parent
fbb8f46fcd
commit
29790a0c1e
|
@ -179,7 +179,7 @@ schema("/clients/:clientid") ->
|
||||||
delete => #{
|
delete => #{
|
||||||
description => <<"Kick out client by client ID">>,
|
description => <<"Kick out client by client ID">>,
|
||||||
parameters => [
|
parameters => [
|
||||||
{clientid, hoconsc:mk(boolean(), #{in => path})}],
|
{clientid, hoconsc:mk(binary(), #{in => path})}],
|
||||||
responses => #{
|
responses => #{
|
||||||
204 => <<"Kick out client successfully">>,
|
204 => <<"Kick out client successfully">>,
|
||||||
404 => emqx_dashboard_swagger:error_codes(
|
404 => emqx_dashboard_swagger:error_codes(
|
||||||
|
@ -258,9 +258,10 @@ schema("/clients/:clientid/unsubscribe") ->
|
||||||
schema("/clients/:clientid/keepalive") ->
|
schema("/clients/:clientid/keepalive") ->
|
||||||
#{
|
#{
|
||||||
'operationId' => set_keepalive,
|
'operationId' => set_keepalive,
|
||||||
post => #{
|
put => #{
|
||||||
description => <<"Set the online client keepalive by seconds">>,
|
description => <<"Set the online client keepalive by seconds">>,
|
||||||
parameters => [{clientid, hoconsc:mk(binary(), #{in => path})}],
|
parameters => [{clientid, hoconsc:mk(binary(), #{in => path})}],
|
||||||
|
'requestBody' => hoconsc:mk(hoconsc:ref(?MODULE, keepalive)),
|
||||||
responses => #{
|
responses => #{
|
||||||
200 => hoconsc:mk(hoconsc:ref(?MODULE, client), #{}),
|
200 => hoconsc:mk(hoconsc:ref(?MODULE, client), #{}),
|
||||||
404 => emqx_dashboard_swagger:error_codes(
|
404 => emqx_dashboard_swagger:error_codes(
|
||||||
|
@ -363,7 +364,7 @@ fields(authz_cache) ->
|
||||||
|
|
||||||
fields(keepalive) ->
|
fields(keepalive) ->
|
||||||
[
|
[
|
||||||
{keepalive, hoconsc:mk(integer(), #{desc => <<"keepalive time, with the unit of second">>})}
|
{interval, hoconsc:mk(integer(), #{desc => <<"Keepalive time, with the unit of second">>})}
|
||||||
];
|
];
|
||||||
|
|
||||||
fields(subscribe) ->
|
fields(subscribe) ->
|
||||||
|
@ -435,13 +436,12 @@ subscriptions(get, #{bindings := #{clientid := ClientID}}) ->
|
||||||
{200, lists:map(Formatter, Subs)}
|
{200, lists:map(Formatter, Subs)}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
set_keepalive(put, #{bindings := #{clientid := ClientID}, query_string := Query}) ->
|
set_keepalive(put, #{bindings := #{clientid := ClientID}, body := Body}) ->
|
||||||
case maps:find(<<"interval">>, Query) of
|
case maps:find(<<"interval">>, Body) of
|
||||||
error -> {404, "Interval Not Found"};
|
error -> {400, 'BAD_REQUEST',"Interval Not Found"};
|
||||||
{ok, Interval0} ->
|
{ok, Interval} ->
|
||||||
Interval = binary_to_integer(Interval0),
|
|
||||||
case emqx_mgmt:set_keepalive(emqx_mgmt_util:urldecode(ClientID), Interval) of
|
case emqx_mgmt:set_keepalive(emqx_mgmt_util:urldecode(ClientID), Interval) of
|
||||||
ok -> {200};
|
ok -> lookup(#{clientid => ClientID});
|
||||||
{error, not_found} ->{404, ?CLIENT_ID_NOT_FOUND};
|
{error, not_found} ->{404, ?CLIENT_ID_NOT_FOUND};
|
||||||
{error, Reason} -> {400, #{code => 'PARAMS_ERROR', message => Reason}}
|
{error, Reason} -> {400, #{code => 'PARAMS_ERROR', message => Reason}}
|
||||||
end
|
end
|
||||||
|
|
|
@ -96,8 +96,9 @@ t_clients(_) ->
|
||||||
%% post /clients/:clientid/unsubscribe
|
%% post /clients/:clientid/unsubscribe
|
||||||
UnSubscribePath = emqx_mgmt_api_test_util:api_path(["clients",
|
UnSubscribePath = emqx_mgmt_api_test_util:api_path(["clients",
|
||||||
binary_to_list(ClientId1), "unsubscribe"]),
|
binary_to_list(ClientId1), "unsubscribe"]),
|
||||||
|
UnSubscribeBody = #{topic => Topic},
|
||||||
{ok, _} = emqx_mgmt_api_test_util:request_api(post, UnSubscribePath,
|
{ok, _} = emqx_mgmt_api_test_util:request_api(post, UnSubscribePath,
|
||||||
"", AuthHeader, SubscribeBody),
|
"", AuthHeader, UnSubscribeBody),
|
||||||
timer:sleep(100),
|
timer:sleep(100),
|
||||||
?assertEqual([], emqx_mgmt:lookup_subscriptions(Client1)),
|
?assertEqual([], emqx_mgmt:lookup_subscriptions(Client1)),
|
||||||
|
|
||||||
|
@ -167,13 +168,13 @@ t_keepalive(_Config) ->
|
||||||
ClientId = "client_keepalive",
|
ClientId = "client_keepalive",
|
||||||
AuthHeader = emqx_mgmt_api_test_util:auth_header_(),
|
AuthHeader = emqx_mgmt_api_test_util:auth_header_(),
|
||||||
Path = emqx_mgmt_api_test_util:api_path(["clients", ClientId, "keepalive"]),
|
Path = emqx_mgmt_api_test_util:api_path(["clients", ClientId, "keepalive"]),
|
||||||
Query = "interval=11",
|
Body = #{interval => 11},
|
||||||
{error,{"HTTP/1.1",404,"Not Found"}} =
|
{error,{"HTTP/1.1",404,"Not Found"}} =
|
||||||
emqx_mgmt_api_test_util:request_api(put, Path, Query, AuthHeader, <<"">>),
|
emqx_mgmt_api_test_util:request_api(put, Path, <<"">>, AuthHeader, Body),
|
||||||
{ok, C1} = emqtt:start_link(#{username => Username, clientid => ClientId}),
|
{ok, C1} = emqtt:start_link(#{username => Username, clientid => ClientId}),
|
||||||
{ok, _} = emqtt:connect(C1),
|
{ok, _} = emqtt:connect(C1),
|
||||||
{ok, Ok} = emqx_mgmt_api_test_util:request_api(put, Path, Query, AuthHeader, <<"">>),
|
{ok, NewClient} = emqx_mgmt_api_test_util:request_api(put, Path, <<"">>, AuthHeader, Body),
|
||||||
?assertEqual("", Ok),
|
#{<<"keepalive">> := 11} = emqx_json:decode(NewClient, [return_maps]),
|
||||||
[Pid] = emqx_cm:lookup_channels(list_to_binary(ClientId)),
|
[Pid] = emqx_cm:lookup_channels(list_to_binary(ClientId)),
|
||||||
#{conninfo := #{keepalive := Keepalive}} = emqx_connection:info(Pid),
|
#{conninfo := #{keepalive := Keepalive}} = emqx_connection:info(Pid),
|
||||||
?assertEqual(11, Keepalive),
|
?assertEqual(11, Keepalive),
|
||||||
|
|
Loading…
Reference in New Issue