http publish
This commit is contained in:
parent
bf28580e65
commit
a318244be0
|
@ -22,6 +22,8 @@
|
||||||
|
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
|
||||||
|
-define(CONTENT_TYPE, "application/x-www-form-urlencoded").
|
||||||
|
|
||||||
all() ->
|
all() ->
|
||||||
[{group, protocol},
|
[{group, protocol},
|
||||||
{group, pubsub},
|
{group, pubsub},
|
||||||
|
@ -62,7 +64,10 @@ groups() ->
|
||||||
[dispatch_retained_messages]},
|
[dispatch_retained_messages]},
|
||||||
{backend, [sequence],
|
{backend, [sequence],
|
||||||
[]},
|
[]},
|
||||||
{http, [sequence], [request_status]},
|
{http, [sequence],
|
||||||
|
[request_status,
|
||||||
|
request_publish
|
||||||
|
]},
|
||||||
{cli, [sequence],
|
{cli, [sequence],
|
||||||
[ctl_register_cmd,
|
[ctl_register_cmd,
|
||||||
cli_status,
|
cli_status,
|
||||||
|
@ -330,6 +335,32 @@ request_status(_) ->
|
||||||
httpc:request(get, {Url, []}, [], []),
|
httpc:request(get, {Url, []}, [], []),
|
||||||
?assertEqual(binary_to_list(Status), Return).
|
?assertEqual(binary_to_list(Status), Return).
|
||||||
|
|
||||||
|
request_publish(_) ->
|
||||||
|
ok = emqttd:subscribe(<<"a/b/c">>, self(), [{qos, 1}]),
|
||||||
|
Params = "qos=1&retain=0&topic=a/b/c&message=hello",
|
||||||
|
?assert(connect_emqttd_publish_(post, "mqtt/publish", Params, auth_header_("", ""))),
|
||||||
|
?assert(receive {dispatch, <<"a/b/c">>, _} -> true after 2 -> false end),
|
||||||
|
emqttd:unsubscribe(<<"a/b/c">>).
|
||||||
|
|
||||||
|
connect_emqttd_publish_(Method, Api, Params, Auth) ->
|
||||||
|
Url = "http://127.0.0.1:8083/" ++ 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.
|
||||||
|
|
||||||
|
auth_header_(User, Pass) ->
|
||||||
|
Encoded = base64:encode_to_string(lists:append([User,":",Pass])),
|
||||||
|
{"Authorization","Basic " ++ Encoded}.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%% cli group
|
%% cli group
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue