Skip to content

Commit

Permalink
test(mqttsn): add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
HJianBo committed May 18, 2023
1 parent c5398ab commit 26b69a5
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions apps/emqx_gateway_mqttsn/test/emqx_sn_protocol_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2259,6 +2259,46 @@ t_clients_subscription_api(_) ->
?assertEqual(<<2, ?SN_DISCONNECT>>, receive_response(Socket)),
gen_udp:close(Socket).

t_clients_api_complex_id(_) ->
ClientId = <<"!@#$%^&*()_+{}:\"<>?/">>,
ClientIdUriEncoded = cow_qs:urlencode(ClientId),
Path = "/gateways/mqttsn/clients/" ++ binary_to_list(ClientIdUriEncoded),
{ok, Socket} = gen_udp:open(0, [binary]),
send_connect_msg(Socket, ClientId),
?assertEqual(<<3, ?SN_CONNACK, 0>>, receive_response(Socket)),
%% get
{200, Client} = request(get, Path),
?assertMatch(#{clientid := ClientId}, Client),
%% subscription list
{200, []} = request(get, Path ++ "/subscriptions"),
%% kickout
{204, _} = request(delete, Path),
gen_udp:close(Socket).

t_update_info_after_subscribed_via_api(_) ->
ClientId = <<"client_id_test1">>,
Path = "/gateways/mqttsn/clients/client_id_test1/subscriptions",
{ok, Socket} = gen_udp:open(0, [binary]),
send_connect_msg(Socket, ClientId),
?assertEqual(<<3, ?SN_CONNACK, 0>>, receive_response(Socket)),
%% create
SubReq = #{
topic => <<"tx">>,
qos => 1,
nl => 0,
rap => 0,
rh => 0
},
{201, _SubsResp} = request(post, Path, SubReq),
timer:sleep(500),
%% assert
{200, Client} = request(get, "/gateways/mqttsn/clients/client_id_test1"),
?assertMatch(#{subscriptions_cnt := 1}, Client),

send_disconnect_msg(Socket, undefined),
?assertEqual(<<2, ?SN_DISCONNECT>>, receive_response(Socket)),
gen_udp:close(Socket).

%%--------------------------------------------------------------------
%% Helper funcs
%%--------------------------------------------------------------------
Expand Down

0 comments on commit 26b69a5

Please sign in to comment.