1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-12-03 19:42:13 +01:00

update tests

This commit is contained in:
Nikolay Kim 2017-11-15 20:28:02 -10:00
parent 0143e18fe9
commit c800bf55f5
2 changed files with 16 additions and 21 deletions

View File

@ -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`

View File

@ -26,18 +26,13 @@
//! payload: Payload, ctx: &mut HttpContext<Self>) -> RouteResult<Self>
//! {
//! // 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());
}
}