aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2019-04-26 20:30:51 +0200
committerLoïc Hoguin <[email protected]>2019-04-26 20:30:51 +0200
commitcee8c6625bd7a09db88daf5e9767cced66fb5c15 (patch)
tree7948616a11e1025c10e60c60f563b6d331d88ee8 /test
parent352206dee80905b10fa9af97f065ce7bee928d87 (diff)
downloadgun-cee8c6625bd7a09db88daf5e9767cced66fb5c15.tar.gz
gun-cee8c6625bd7a09db88daf5e9767cced66fb5c15.tar.bz2
gun-cee8c6625bd7a09db88daf5e9767cced66fb5c15.zip
Add upgrade/ws tuples to gun:await/2,3,4
Diffstat (limited to 'test')
-rw-r--r--test/ws_SUITE.erl19
1 files changed, 17 insertions, 2 deletions
diff --git a/test/ws_SUITE.erl b/test/ws_SUITE.erl
index 8cb6bd1..1a48b83 100644
--- a/test/ws_SUITE.erl
+++ b/test/ws_SUITE.erl
@@ -28,8 +28,12 @@ groups() ->
[{ws, [], ct_helper:all(?MODULE)}].
init_per_suite(Config) ->
+ Routes = [
+ {"/", ws_echo, []},
+ {"/reject", ws_reject_h, []}
+ ],
{ok, _} = cowboy:start_clear(ws, [], #{env => #{
- dispatch => cowboy_router:compile([{'_', [{"/", ws_reject_h, []}]}])
+ dispatch => cowboy_router:compile([{'_', Routes}])
}}),
Port = ranch:get_port(ws),
[{port, Port}|Config].
@@ -39,11 +43,22 @@ end_per_suite(_) ->
%% Tests.
+await(Config) ->
+ doc("Ensure gun:await/2 can be used to receive Websocket frames."),
+ {ok, ConnPid} = gun:open("localhost", config(port, Config)),
+ {ok, _} = gun:await_up(ConnPid),
+ StreamRef = gun:ws_upgrade(ConnPid, "/", []),
+ {upgrade, [<<"websocket">>], _} = gun:await(ConnPid, StreamRef),
+ Frame = {text, <<"Hello!">>},
+ gun:ws_send(ConnPid, Frame),
+ {ws, Frame} = gun:await(ConnPid, StreamRef),
+ gun:close(ConnPid).
+
reject_upgrade(Config) ->
doc("Ensure Websocket connections can be rejected."),
{ok, ConnPid} = gun:open("localhost", config(port, Config)),
{ok, _} = gun:await_up(ConnPid),
- StreamRef = gun:ws_upgrade(ConnPid, "/", []),
+ StreamRef = gun:ws_upgrade(ConnPid, "/reject", []),
receive
{gun_response, ConnPid, StreamRef, nofin, 400, _} ->
{ok, <<"Upgrade rejected">>} = gun:await_body(ConnPid, StreamRef, 1000),