1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-06-12 02:09:36 +00:00

add ws close description parse test

This commit is contained in:
Nathan Fox 2018-04-21 17:20:23 -04:00
parent 507361c1df
commit b7b61afacc
2 changed files with 12 additions and 1 deletions

View file

@ -179,7 +179,7 @@ impl From<u16> for CloseCode {
}
}
#[derive(Debug, PartialEq)]
#[derive(Debug, Eq, PartialEq, Clone)]
pub struct CloseReason {
pub code: CloseCode,
pub description: Option<String>,

View file

@ -70,6 +70,17 @@ fn test_empty_close_code() {
assert_eq!(item, Some(ws::Message::Close(None)));
}
#[test]
fn test_close_description() {
let mut srv = test::TestServer::new(|app| app.handler(|req| ws::start(req, Ws)));
let (reader, mut writer) = srv.ws().unwrap();
let close_reason:ws::CloseReason = (ws::CloseCode::Normal, "close description").into();
writer.close(Some(close_reason.clone()));
let (item, _) = srv.execute(reader.into_future()).unwrap();
assert_eq!(item, Some(ws::Message::Close(Some(close_reason))));
}
#[test]
fn test_large_text() {
let data = rand::thread_rng()