Skip to content

Commit

Permalink
Merge branch 'feat/432' of github.com:jrconlin/actix-web into feat/432
Browse files Browse the repository at this point in the history
  • Loading branch information
jrconlin committed Aug 1, 2018
2 parents 115f59d + 246eafb commit 97ada3d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

* Support HTTP/2 with rustls #36

* Allow TestServer to open a websocket on any URL # 433

### Fixed

* Do not override HOST header for client request #428
Expand All @@ -22,7 +24,7 @@
* Add implementation of `FromRequest<S>` for `Option<T>` and `Result<T, Error>`

* Allow to handle application prefix, i.e. allow to handle `/app` path
for application with `/app` prefix.
for application with `/app` prefix.
Check [`App::prefix()`](https://actix.rs/actix-web/actix_web/struct.App.html#method.prefix)
api doc.

Expand Down
40 changes: 40 additions & 0 deletions tests/test_ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,46 @@ fn test_simple() {
);
}

// websocket resource helper function
fn start_ws_resource(req: &HttpRequest) -> Result<HttpResponse, Error> {
ws::start(req, Ws)
}

#[test]
fn test_simple_path() {
const PATH:&str = "/v1/ws/";

// Create a websocket at a specific path.
let mut srv = test::TestServer::new(|app| {
app.resource(PATH, |r| r.route().f(start_ws_resource));
});
// fetch the sockets for the resource at a given path.
let (reader, mut writer) = srv.ws_at(PATH).unwrap();

writer.text("text");
let (item, reader) = srv.execute(reader.into_future()).unwrap();
assert_eq!(item, Some(ws::Message::Text("text".to_owned())));

writer.binary(b"text".as_ref());
let (item, reader) = srv.execute(reader.into_future()).unwrap();
assert_eq!(
item,
Some(ws::Message::Binary(Bytes::from_static(b"text").into()))
);

writer.ping("ping");
let (item, reader) = srv.execute(reader.into_future()).unwrap();
assert_eq!(item, Some(ws::Message::Pong("ping".to_owned())));

writer.close(Some(ws::CloseCode::Normal.into()));
let (item, _) = srv.execute(reader.into_future()).unwrap();
assert_eq!(
item,
Some(ws::Message::Close(Some(ws::CloseCode::Normal.into())))
);
}


#[test]
fn test_empty_close_code() {
let mut srv = test::TestServer::new(|app| app.handler(|req| ws::start(req, Ws)));
Expand Down

0 comments on commit 97ada3d

Please sign in to comment.