diff --git a/test/emqx_SUITE.erl b/test/emqx_SUITE.erl index 472069464..5cf671125 100644 --- a/test/emqx_SUITE.erl +++ b/test/emqx_SUITE.erl @@ -404,65 +404,19 @@ request_status(_) -> ?assertEqual(binary_to_list(Status), Return). request_publish(_) -> - application:start(emq_dashboard), emqttc:start_link([{host, "localhost"}, {port, 1883}, {client_id, <<"random">>}, {clean_sess, false}]), 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}]), 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), UnSubParams = "{\"topic\" : \"a\/b\/c\", \"client_id\" :\"random\"}", - ?assert(connect_emqx_pubsub_(post, "api/v2/mqtt/unsubscribe", UnSubParams, auth_header_("admin", "public"))). - -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)). + ?assert(connect_emqx_pubsub_(post, "api/v2/mqtt/unsubscribe", UnSubParams, auth_header_("", ""))). connect_emqx_publish_(Method, Api, Params, Auth) -> Url = "http://127.0.0.1:8080/" ++ Api, @@ -657,6 +611,51 @@ cleanSession_validate1(_) -> emqttc:disconnect(Pub), 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({error, {already_started, _}}) -> ok. diff --git a/test/emqx_lib_SUITE.erl b/test/emqx_lib_SUITE.erl index e39b8178d..4f6bc8996 100644 --- a/test/emqx_lib_SUITE.erl +++ b/test/emqx_lib_SUITE.erl @@ -152,12 +152,12 @@ time_now_to_(_) -> node_is_aliving(_) -> io:format("Node: ~p~n", [node()]), - true = emqx_node:is_aliving(node()), - false = emqx_node:is_aliving('x@127.0.0.1'). + true = ekka_node:is_aliving(node()), + false = ekka_node:is_aliving('x@127.0.0.1'). node_parse_name(_) -> - 'a@127.0.0.1' = emqx_node:parse_name("a@127.0.0.1"), - 'b@127.0.0.1' = emqx_node:parse_name("b"). + 'a@127.0.0.1' = ekka_node:parse_name("a@127.0.0.1"), + 'b@127.0.0.1' = ekka_node:parse_name("b"). %%-------------------------------------------------------------------- %% base62 encode decode diff --git a/test/emqx_router_SUITE.erl b/test/emqx_router_SUITE.erl index 51db6c506..72ce4e5f0 100644 --- a/test/emqx_router_SUITE.erl +++ b/test/emqx_router_SUITE.erl @@ -126,10 +126,6 @@ clear_tables() -> ?R:clean_local_routes(), lists:foreach(fun mnesia:clear_table/1, [mqtt_route, mqtt_trie, mqtt_trie_node]). -%%-------------------------------------------------------------------- -%% Router Test -%%-------------------------------------------------------------------- - router_add_del(_) -> %% Add ?R:add_route(<<"#">>),