fix(gateway): fix test case error

This commit is contained in:
firest 2022-08-29 15:27:11 +08:00
parent 527ea23ec8
commit 81a86e3202
5 changed files with 30 additions and 30 deletions

View File

@ -255,37 +255,37 @@ t_clients_api(_) ->
Fun = fun(_Channel, _Token) -> Fun = fun(_Channel, _Token) ->
ClientId = <<"client1">>, ClientId = <<"client1">>,
%% list %% list
{200, #{data := [Client1]}} = request(get, "/gateway/coap/clients"), {200, #{data := [Client1]}} = request(get, "/gateways/coap/clients"),
#{clientid := ClientId} = Client1, #{clientid := ClientId} = Client1,
%% searching %% searching
{200, #{data := [Client2]}} = {200, #{data := [Client2]}} =
request( request(
get, get,
"/gateway/coap/clients", "/gateways/coap/clients",
[{<<"clientid">>, ClientId}] [{<<"clientid">>, ClientId}]
), ),
{200, #{data := [Client3]}} = {200, #{data := [Client3]}} =
request( request(
get, get,
"/gateway/coap/clients", "/gateways/coap/clients",
[{<<"like_clientid">>, <<"cli">>}] [{<<"like_clientid">>, <<"cli">>}]
), ),
%% lookup %% lookup
{200, Client4} = {200, Client4} =
request(get, "/gateway/coap/clients/client1"), request(get, "/gateways/coap/clients/client1"),
%% assert %% assert
Client1 = Client2 = Client3 = Client4, Client1 = Client2 = Client3 = Client4,
%% kickout %% kickout
{204, _} = {204, _} =
request(delete, "/gateway/coap/clients/client1"), request(delete, "/gateways/coap/clients/client1"),
timer:sleep(200), timer:sleep(200),
{200, #{data := []}} = request(get, "/gateway/coap/clients") {200, #{data := []}} = request(get, "/gateways/coap/clients")
end, end,
with_connection(Fun). with_connection(Fun).
t_clients_subscription_api(_) -> t_clients_subscription_api(_) ->
Fun = fun(_Channel, _Token) -> Fun = fun(_Channel, _Token) ->
Path = "/gateway/coap/clients/client1/subscriptions", Path = "/gateways/coap/clients/client1/subscriptions",
%% list %% list
{200, []} = request(get, Path), {200, []} = request(get, Path),
%% create %% create
@ -312,7 +312,7 @@ t_clients_subscription_api(_) ->
t_clients_get_subscription_api(_) -> t_clients_get_subscription_api(_) ->
Fun = fun(Channel, Token) -> Fun = fun(Channel, Token) ->
Path = "/gateway/coap/clients/client1/subscriptions", Path = "/gateways/coap/clients/client1/subscriptions",
%% list %% list
{200, []} = request(get, Path), {200, []} = request(get, Path),
@ -333,14 +333,14 @@ t_on_offline_event(_) ->
emqx_hooks:add('client.connected', {emqx_sys, on_client_connected, []}, 1000), emqx_hooks:add('client.connected', {emqx_sys, on_client_connected, []}, 1000),
emqx_hooks:add('client.disconnected', {emqx_sys, on_client_disconnected, []}, 1000), emqx_hooks:add('client.disconnected', {emqx_sys, on_client_disconnected, []}, 1000),
ConnectedSub = <<"$SYS/brokers/+/gateway/coap/clients/+/connected">>, ConnectedSub = <<"$SYS/brokers/+/gateways/coap/clients/+/connected">>,
emqx_broker:subscribe(ConnectedSub), emqx_broker:subscribe(ConnectedSub),
timer:sleep(100), timer:sleep(100),
Token = connection(Channel), Token = connection(Channel),
?assertMatch(#message{}, receive_deliver(500)), ?assertMatch(#message{}, receive_deliver(500)),
DisconnectedSub = <<"$SYS/brokers/+/gateway/coap/clients/+/disconnected">>, DisconnectedSub = <<"$SYS/brokers/+/gateways/coap/clients/+/disconnected">>,
emqx_broker:subscribe(DisconnectedSub), emqx_broker:subscribe(DisconnectedSub),
timer:sleep(100), timer:sleep(100),

View File

@ -141,7 +141,7 @@ on_start_auth(authn_http) ->
%% set authn for gateway %% set authn for gateway
Setup = fun(Gateway) -> Setup = fun(Gateway) ->
Path = io_lib:format("/gateway/~ts/authentication", [Gateway]), Path = io_lib:format("/gateways/~ts/authentication", [Gateway]),
{204, _} = request(delete, Path), {204, _} = request(delete, Path),
timer:sleep(200), timer:sleep(200),
{201, _} = request(post, Path, http_authn_config()), {201, _} = request(post, Path, http_authn_config()),
@ -198,7 +198,7 @@ on_start_auth(authz_http) ->
on_stop_auth(authn_http) -> on_stop_auth(authn_http) ->
Delete = fun(Gateway) -> Delete = fun(Gateway) ->
Path = io_lib:format("/gateway/~ts/authentication", [Gateway]), Path = io_lib:format("/gateways/~ts/authentication", [Gateway]),
{204, _} = request(delete, Path) {204, _} = request(delete, Path)
end, end,
lists:foreach(Delete, ?GATEWAYS), lists:foreach(Delete, ?GATEWAYS),

View File

@ -2353,18 +2353,18 @@ case100_clients_api(Config) ->
std_register(UdpSock, Epn, ObjectList, MsgId1, RespTopic), std_register(UdpSock, Epn, ObjectList, MsgId1, RespTopic),
%% list %% list
{200, #{data := [Client1]}} = request(get, "/gateway/lwm2m/clients"), {200, #{data := [Client1]}} = request(get, "/gateways/lwm2m/clients"),
%% searching %% searching
{200, #{data := [Client2]}} = {200, #{data := [Client2]}} =
request( request(
get, get,
"/gateway/lwm2m/clients", "/gateways/lwm2m/clients",
[{<<"endpoint_name">>, list_to_binary(Epn)}] [{<<"endpoint_name">>, list_to_binary(Epn)}]
), ),
{200, #{data := [Client3]}} = {200, #{data := [Client3]}} =
request( request(
get, get,
"/gateway/lwm2m/clients", "/gateways/lwm2m/clients",
[ [
{<<"like_endpoint_name">>, list_to_binary(Epn)}, {<<"like_endpoint_name">>, list_to_binary(Epn)},
{<<"gte_lifetime">>, <<"1">>} {<<"gte_lifetime">>, <<"1">>}
@ -2373,14 +2373,14 @@ case100_clients_api(Config) ->
%% lookup %% lookup
ClientId = maps:get(clientid, Client1), ClientId = maps:get(clientid, Client1),
{200, Client4} = {200, Client4} =
request(get, "/gateway/lwm2m/clients/" ++ binary_to_list(ClientId)), request(get, "/gateways/lwm2m/clients/" ++ binary_to_list(ClientId)),
%% assert %% assert
Client1 = Client2 = Client3 = Client4, Client1 = Client2 = Client3 = Client4,
%% kickout %% kickout
{204, _} = {204, _} =
request(delete, "/gateway/lwm2m/clients/" ++ binary_to_list(ClientId)), request(delete, "/gateways/lwm2m/clients/" ++ binary_to_list(ClientId)),
timer:sleep(100), timer:sleep(100),
{200, #{data := []}} = request(get, "/gateway/lwm2m/clients"). {200, #{data := []}} = request(get, "/gateways/lwm2m/clients").
case100_subscription_api(Config) -> case100_subscription_api(Config) ->
Epn = "urn:oma:lwm2m:oma:3", Epn = "urn:oma:lwm2m:oma:3",
@ -2390,10 +2390,10 @@ case100_subscription_api(Config) ->
RespTopic = list_to_binary("lwm2m/" ++ Epn ++ "/up/resp"), RespTopic = list_to_binary("lwm2m/" ++ Epn ++ "/up/resp"),
std_register(UdpSock, Epn, ObjectList, MsgId1, RespTopic), std_register(UdpSock, Epn, ObjectList, MsgId1, RespTopic),
{200, #{data := [Client1]}} = request(get, "/gateway/lwm2m/clients"), {200, #{data := [Client1]}} = request(get, "/gateways/lwm2m/clients"),
ClientId = maps:get(clientid, Client1), ClientId = maps:get(clientid, Client1),
Path = Path =
"/gateway/lwm2m/clients/" ++ "/gateways/lwm2m/clients/" ++
binary_to_list(ClientId) ++ binary_to_list(ClientId) ++
"/subscriptions", "/subscriptions",

View File

@ -2198,15 +2198,15 @@ t_clients_api(_) ->
send_connect_msg(Socket, ClientId), send_connect_msg(Socket, ClientId),
?assertEqual(<<3, ?SN_CONNACK, 0>>, receive_response(Socket)), ?assertEqual(<<3, ?SN_CONNACK, 0>>, receive_response(Socket)),
%% list %% list
{200, #{data := [Client1]}} = request(get, "/gateway/mqttsn/clients"), {200, #{data := [Client1]}} = request(get, "/gateways/mqttsn/clients"),
#{clientid := ClientId} = Client1, #{clientid := ClientId} = Client1,
%% searching %% searching
{200, #{data := [Client2]}} = {200, #{data := [Client2]}} =
request(get, "/gateway/mqttsn/clients", [{<<"clientid">>, ClientId}]), request(get, "/gateways/mqttsn/clients", [{<<"clientid">>, ClientId}]),
{200, #{data := [Client3]}} = {200, #{data := [Client3]}} =
request( request(
get, get,
"/gateway/mqttsn/clients", "/gateways/mqttsn/clients",
[ [
{<<"like_clientid">>, <<"test1">>}, {<<"like_clientid">>, <<"test1">>},
{<<"proto_ver">>, <<"1.2">>}, {<<"proto_ver">>, <<"1.2">>},
@ -2218,21 +2218,21 @@ t_clients_api(_) ->
), ),
%% lookup %% lookup
{200, Client4} = {200, Client4} =
request(get, "/gateway/mqttsn/clients/client_id_test1"), request(get, "/gateways/mqttsn/clients/client_id_test1"),
%% assert %% assert
Client1 = Client2 = Client3 = Client4, Client1 = Client2 = Client3 = Client4,
%% kickout %% kickout
{204, _} = {204, _} =
request(delete, "/gateway/mqttsn/clients/client_id_test1"), request(delete, "/gateways/mqttsn/clients/client_id_test1"),
timer:sleep(100), timer:sleep(100),
{200, #{data := []}} = request(get, "/gateway/mqttsn/clients"), {200, #{data := []}} = request(get, "/gateways/mqttsn/clients"),
send_disconnect_msg(Socket, undefined), send_disconnect_msg(Socket, undefined),
gen_udp:close(Socket). gen_udp:close(Socket).
t_clients_subscription_api(_) -> t_clients_subscription_api(_) ->
ClientId = <<"client_id_test1">>, ClientId = <<"client_id_test1">>,
Path = "/gateway/mqttsn/clients/client_id_test1/subscriptions", Path = "/gateways/mqttsn/clients/client_id_test1/subscriptions",
{ok, Socket} = gen_udp:open(0, [binary]), {ok, Socket} = gen_udp:open(0, [binary]),
send_connect_msg(Socket, ClientId), send_connect_msg(Socket, ClientId),
?assertEqual(<<3, ?SN_CONNACK, 0>>, receive_response(Socket)), ?assertEqual(<<3, ?SN_CONNACK, 0>>, receive_response(Socket)),

View File

@ -721,12 +721,12 @@ t_rest_clienit_info(_) ->
_, _} = parse(Data), _, _} = parse(Data),
%% client lists %% client lists
{200, Clients} = request(get, "/gateway/stomp/clients"), {200, Clients} = request(get, "/gateways/stomp/clients"),
?assertEqual(1, length(maps:get(data, Clients))), ?assertEqual(1, length(maps:get(data, Clients))),
StompClient = lists:nth(1, maps:get(data, Clients)), StompClient = lists:nth(1, maps:get(data, Clients)),
ClientId = maps:get(clientid, StompClient), ClientId = maps:get(clientid, StompClient),
ClientPath = ClientPath =
"/gateway/stomp/clients/" ++ "/gateways/stomp/clients/" ++
binary_to_list(ClientId), binary_to_list(ClientId),
{200, StompClient1} = request(get, ClientPath), {200, StompClient1} = request(get, ClientPath),
?assertEqual(StompClient, StompClient1), ?assertEqual(StompClient, StompClient1),
@ -811,7 +811,7 @@ t_rest_clienit_info(_) ->
% sync % sync
ignored = gen_server:call(emqx_cm, ignore, infinity), ignored = gen_server:call(emqx_cm, ignore, infinity),
ok = emqx_pool:flush_async_tasks(), ok = emqx_pool:flush_async_tasks(),
{200, Clients2} = request(get, "/gateway/stomp/clients"), {200, Clients2} = request(get, "/gateways/stomp/clients"),
?assertEqual(0, length(maps:get(data, Clients2))) ?assertEqual(0, length(maps:get(data, Clients2)))
end). end).