Update test cases
This commit is contained in:
parent
a904dfd4f2
commit
c8d6e9a012
|
@ -404,65 +404,19 @@ request_status(_) ->
|
||||||
?assertEqual(binary_to_list(Status), Return).
|
?assertEqual(binary_to_list(Status), Return).
|
||||||
|
|
||||||
request_publish(_) ->
|
request_publish(_) ->
|
||||||
application:start(emq_dashboard),
|
|
||||||
emqttc:start_link([{host, "localhost"},
|
emqttc:start_link([{host, "localhost"},
|
||||||
{port, 1883},
|
{port, 1883},
|
||||||
{client_id, <<"random">>},
|
{client_id, <<"random">>},
|
||||||
{clean_sess, false}]),
|
{clean_sess, false}]),
|
||||||
SubParams = "{\"qos\":1, \"topic\" : \"a\/b\/c\", \"client_id\" :\"random\"}",
|
SubParams = "{\"qos\":1, \"topic\" : \"a\/b\/c\", \"client_id\" :\"random\"}",
|
||||||
?assert(connect_emqx_pubsub_(post, "api/v2/mqtt/subscribe", SubParams, auth_header_("admin", "public"))),
|
?assert(connect_emqx_pubsub_(post, "api/v2/mqtt/subscribe", SubParams, auth_header_("", ""))),
|
||||||
ok = emqx:subscribe(<<"a/b/c">>, self(), [{qos, 1}]),
|
ok = emqx:subscribe(<<"a/b/c">>, self(), [{qos, 1}]),
|
||||||
Params = "{\"qos\":1, \"retain\":false, \"topic\" : \"a\/b\/c\", \"messages\" :\"hello\"}",
|
Params = "{\"qos\":1, \"retain\":false, \"topic\" : \"a\/b\/c\", \"messages\" :\"hello\"}",
|
||||||
?assert(connect_emqx_pubsub_(post, "api/v2/mqtt/publish", Params, auth_header_("admin", "public"))),
|
?assert(connect_emqx_pubsub_(post, "api/v2/mqtt/publish", Params, auth_header_("", ""))),
|
||||||
?assert(receive {dispatch, <<"a/b/c">>, _} -> true after 2 -> false end),
|
?assert(receive {dispatch, <<"a/b/c">>, _} -> true after 2 -> false end),
|
||||||
|
|
||||||
UnSubParams = "{\"topic\" : \"a\/b\/c\", \"client_id\" :\"random\"}",
|
UnSubParams = "{\"topic\" : \"a\/b\/c\", \"client_id\" :\"random\"}",
|
||||||
?assert(connect_emqx_pubsub_(post, "api/v2/mqtt/unsubscribe", UnSubParams, auth_header_("admin", "public"))).
|
?assert(connect_emqx_pubsub_(post, "api/v2/mqtt/unsubscribe", UnSubParams, auth_header_("", ""))).
|
||||||
|
|
||||||
connect_emqx_pubsub_(Method, Api, Params, Auth) ->
|
|
||||||
Url = "http://127.0.0.1:8080/" ++ Api,
|
|
||||||
case httpc:request(Method, {Url, [Auth], ?CONTENT_TYPE, Params}, [], []) of
|
|
||||||
{error, socket_closed_remotely} ->
|
|
||||||
false;
|
|
||||||
{ok, {{"HTTP/1.1", 200, "OK"}, _, _Return} } ->
|
|
||||||
true;
|
|
||||||
{ok, {{"HTTP/1.1", 400, _}, _, []}} ->
|
|
||||||
false;
|
|
||||||
{ok, {{"HTTP/1.1", 404, _}, _, []}} ->
|
|
||||||
false
|
|
||||||
end.
|
|
||||||
|
|
||||||
request(Path) ->
|
|
||||||
http_get(get, Path).
|
|
||||||
|
|
||||||
http_get(Method, Path) ->
|
|
||||||
req(Method, Path, []).
|
|
||||||
|
|
||||||
http_put(Method, Path, Params) ->
|
|
||||||
req(Method, Path, format_for_upload(Params)).
|
|
||||||
|
|
||||||
http_post(Method, Path, Params) ->
|
|
||||||
req(Method, Path, format_for_upload(Params)).
|
|
||||||
|
|
||||||
req(Method, Path, Body) ->
|
|
||||||
Url = ?URL ++ Path,
|
|
||||||
Headers = auth_header_("", ""),
|
|
||||||
case httpc:request(Method, {Url, [Headers]}, [], []) of
|
|
||||||
{error, R} ->
|
|
||||||
ct:log("R:~p~n", [R]),
|
|
||||||
false;
|
|
||||||
{ok, {{"HTTP/1.1", 200, "OK"}, _, _Return} } ->
|
|
||||||
true;
|
|
||||||
{ok, {{"HTTP/1.1", 400, _}, _, []}} ->
|
|
||||||
false;
|
|
||||||
{ok, {{"HTTP/1.1", 404, _}, _, []}} ->
|
|
||||||
false
|
|
||||||
end.
|
|
||||||
|
|
||||||
format_for_upload(none) ->
|
|
||||||
<<"">>;
|
|
||||||
format_for_upload(List) ->
|
|
||||||
iolist_to_binary(mochijson2:encode(List)).
|
|
||||||
|
|
||||||
connect_emqx_publish_(Method, Api, Params, Auth) ->
|
connect_emqx_publish_(Method, Api, Params, Auth) ->
|
||||||
Url = "http://127.0.0.1:8080/" ++ Api,
|
Url = "http://127.0.0.1:8080/" ++ Api,
|
||||||
|
@ -657,6 +611,51 @@ cleanSession_validate1(_) ->
|
||||||
emqttc:disconnect(Pub),
|
emqttc:disconnect(Pub),
|
||||||
emqttc:disconnect(C11).
|
emqttc:disconnect(C11).
|
||||||
|
|
||||||
|
connect_emqx_pubsub_(Method, Api, Params, Auth) ->
|
||||||
|
Url = "http://127.0.0.1:8080/" ++ Api,
|
||||||
|
case httpc:request(Method, {Url, [Auth], ?CONTENT_TYPE, Params}, [], []) of
|
||||||
|
{error, socket_closed_remotely} ->
|
||||||
|
false;
|
||||||
|
{ok, {{"HTTP/1.1", 200, "OK"}, _, _Return} } ->
|
||||||
|
true;
|
||||||
|
{ok, {{"HTTP/1.1", 400, _}, _, []}} ->
|
||||||
|
false;
|
||||||
|
{ok, {{"HTTP/1.1", 404, _}, _, []}} ->
|
||||||
|
false
|
||||||
|
end.
|
||||||
|
|
||||||
|
request(Path) ->
|
||||||
|
http_get(get, Path).
|
||||||
|
|
||||||
|
http_get(Method, Path) ->
|
||||||
|
req(Method, Path, []).
|
||||||
|
|
||||||
|
http_put(Method, Path, Params) ->
|
||||||
|
req(Method, Path, format_for_upload(Params)).
|
||||||
|
|
||||||
|
http_post(Method, Path, Params) ->
|
||||||
|
req(Method, Path, format_for_upload(Params)).
|
||||||
|
|
||||||
|
req(Method, Path, Body) ->
|
||||||
|
Url = ?URL ++ Path,
|
||||||
|
Headers = auth_header_("", ""),
|
||||||
|
case httpc:request(Method, {Url, [Headers]}, [], []) of
|
||||||
|
{error, R} ->
|
||||||
|
ct:log("R:~p~n", [R]),
|
||||||
|
false;
|
||||||
|
{ok, {{"HTTP/1.1", 200, "OK"}, _, _Return} } ->
|
||||||
|
true;
|
||||||
|
{ok, {{"HTTP/1.1", 400, _}, _, []}} ->
|
||||||
|
false;
|
||||||
|
{ok, {{"HTTP/1.1", 404, _}, _, []}} ->
|
||||||
|
false
|
||||||
|
end.
|
||||||
|
|
||||||
|
format_for_upload(none) ->
|
||||||
|
<<"">>;
|
||||||
|
format_for_upload(List) ->
|
||||||
|
iolist_to_binary(mochijson2:encode(List)).
|
||||||
|
|
||||||
ensure_ok(ok) -> ok;
|
ensure_ok(ok) -> ok;
|
||||||
ensure_ok({error, {already_started, _}}) -> ok.
|
ensure_ok({error, {already_started, _}}) -> ok.
|
||||||
|
|
||||||
|
|
|
@ -152,12 +152,12 @@ time_now_to_(_) ->
|
||||||
|
|
||||||
node_is_aliving(_) ->
|
node_is_aliving(_) ->
|
||||||
io:format("Node: ~p~n", [node()]),
|
io:format("Node: ~p~n", [node()]),
|
||||||
true = emqx_node:is_aliving(node()),
|
true = ekka_node:is_aliving(node()),
|
||||||
false = emqx_node:is_aliving('x@127.0.0.1').
|
false = ekka_node:is_aliving('x@127.0.0.1').
|
||||||
|
|
||||||
node_parse_name(_) ->
|
node_parse_name(_) ->
|
||||||
'a@127.0.0.1' = emqx_node:parse_name("a@127.0.0.1"),
|
'a@127.0.0.1' = ekka_node:parse_name("a@127.0.0.1"),
|
||||||
'b@127.0.0.1' = emqx_node:parse_name("b").
|
'b@127.0.0.1' = ekka_node:parse_name("b").
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% base62 encode decode
|
%% base62 encode decode
|
||||||
|
|
|
@ -126,10 +126,6 @@ clear_tables() ->
|
||||||
?R:clean_local_routes(),
|
?R:clean_local_routes(),
|
||||||
lists:foreach(fun mnesia:clear_table/1, [mqtt_route, mqtt_trie, mqtt_trie_node]).
|
lists:foreach(fun mnesia:clear_table/1, [mqtt_route, mqtt_trie, mqtt_trie_node]).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
|
||||||
%% Router Test
|
|
||||||
%%--------------------------------------------------------------------
|
|
||||||
|
|
||||||
router_add_del(_) ->
|
router_add_del(_) ->
|
||||||
%% Add
|
%% Add
|
||||||
?R:add_route(<<"#">>),
|
?R:add_route(<<"#">>),
|
||||||
|
|
Loading…
Reference in New Issue