From c800bf55f5a632abb320b6b890d741413133e12a Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Wed, 15 Nov 2017 20:28:02 -1000 Subject: [PATCH] update tests --- src/error.rs | 4 ++-- src/ws.rs | 33 ++++++++++++++------------------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/error.rs b/src/error.rs index 5cf9ef947..db3087e01 100644 --- a/src/error.rs +++ b/src/error.rs @@ -98,10 +98,10 @@ pub enum ParseError { Timeout, /// An `io::Error` that occurred while trying to read or write to a network stream. #[fail(display="IO error: {}", _0)] - Io(IoError), + Io(#[cause] IoError), /// Parsing a field as string failed #[fail(display="UTF8 error: {}", _0)] - Utf8(Utf8Error), + Utf8(#[cause] Utf8Error), } /// Return `BadRequest` for `ParseError` diff --git a/src/ws.rs b/src/ws.rs index b7e45dd2b..ab1f6983c 100644 --- a/src/ws.rs +++ b/src/ws.rs @@ -26,18 +26,13 @@ //! payload: Payload, ctx: &mut HttpContext) -> RouteResult //! { //! // WebSocket handshake -//! match ws::handshake(&req) { -//! Ok(resp) => { -//! // Send handshake response to peer -//! ctx.start(resp); -//! // Map Payload into WsStream -//! ctx.add_stream(ws::WsStream::new(payload)); -//! // Start ws messages processing -//! Reply::async(WsRoute) -//! }, -//! Err(err) => -//! Reply::reply(err) -//! } +//! let resp = ws::handshake(&req)?; +//! // Send handshake response to peer +//! ctx.start(resp); +//! // Map Payload into WsStream +//! ctx.add_stream(ws::WsStream::new(payload)); +//! // Start ws messages processing +//! Reply::async(WsRoute) //! } //! } //! @@ -345,21 +340,21 @@ mod tests { let req = HttpRequest::new(Method::GET, "/".to_owned(), Version::HTTP_11, HeaderMap::new(), String::new()); - assert_eq!(WsHandshakeError::GetMethodRequired, handshake(&req).err().unwrap()); + assert_eq!(WsHandshakeError::NoWebsocketUpgrade, handshake(&req).err().unwrap()); let mut headers = HeaderMap::new(); headers.insert(header::UPGRADE, header::HeaderValue::from_static("test")); let req = HttpRequest::new(Method::GET, "/".to_owned(), Version::HTTP_11, headers, String::new()); - assert_eq!(WsHandshakeError::GetMethodRequired, handshake(&req).err().unwrap()); + assert_eq!(WsHandshakeError::NoWebsocketUpgrade, handshake(&req).err().unwrap()); let mut headers = HeaderMap::new(); headers.insert(header::UPGRADE, header::HeaderValue::from_static("websocket")); let req = HttpRequest::new(Method::GET, "/".to_owned(), Version::HTTP_11, headers, String::new()); - assert_eq!(WsHandshakeError::GetMethodRequired, handshake(&req).err().unwrap()); + assert_eq!(WsHandshakeError::NoConnectionUpgrade, handshake(&req).err().unwrap()); let mut headers = HeaderMap::new(); headers.insert(header::UPGRADE, @@ -368,7 +363,7 @@ mod tests { header::HeaderValue::from_static("upgrade")); let req = HttpRequest::new(Method::GET, "/".to_owned(), Version::HTTP_11, headers, String::new()); - assert_eq!(WsHandshakeError::GetMethodRequired, handshake(&req).err().unwrap()); + assert_eq!(WsHandshakeError::NoVersionHeader, handshake(&req).err().unwrap()); let mut headers = HeaderMap::new(); headers.insert(header::UPGRADE, @@ -379,7 +374,7 @@ mod tests { header::HeaderValue::from_static("5")); let req = HttpRequest::new(Method::GET, "/".to_owned(), Version::HTTP_11, headers, String::new()); - assert_eq!(WsHandshakeError::GetMethodRequired, handshake(&req).err().unwrap()); + assert_eq!(WsHandshakeError::UnsupportedVersion, handshake(&req).err().unwrap()); let mut headers = HeaderMap::new(); headers.insert(header::UPGRADE, @@ -390,7 +385,7 @@ mod tests { header::HeaderValue::from_static("13")); let req = HttpRequest::new(Method::GET, "/".to_owned(), Version::HTTP_11, headers, String::new()); - assert_eq!(WsHandshakeError::GetMethodRequired, handshake(&req).err().unwrap()); + assert_eq!(WsHandshakeError::BadWebsocketKey, handshake(&req).err().unwrap()); let mut headers = HeaderMap::new(); headers.insert(header::UPGRADE, @@ -403,6 +398,6 @@ mod tests { header::HeaderValue::from_static("13")); let req = HttpRequest::new(Method::GET, "/".to_owned(), Version::HTTP_11, headers, String::new()); - assert_eq!(WsHandshakeError::GetMethodRequired, handshake(&req).err().unwrap()); + assert_eq!(StatusCode::SWITCHING_PROTOCOLS, handshake(&req).unwrap().status()); } }