diff options
Diffstat (limited to 'test/ws_SUITE.erl')
-rw-r--r-- | test/ws_SUITE.erl | 19 |
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), |