1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-23 16:21:06 +01:00

response tests

This commit is contained in:
Nikolay Kim 2017-10-22 22:54:11 -07:00
parent e8936fe081
commit f4180e78fe

View File

@ -172,8 +172,11 @@ impl HttpResponse {
/// Keep-alive status for this connection
pub fn keep_alive(&self) -> Option<bool> {
if let Some(ConnectionType::KeepAlive) = self.connection_type {
Some(true)
if let Some(ct) = self.connection_type {
match ct {
ConnectionType::KeepAlive => Some(true),
ConnectionType::Close | ConnectionType::Upgrade => Some(false),
}
} else {
None
}
@ -406,3 +409,35 @@ fn parts<'a>(parts: &'a mut Option<Parts>, err: &Option<HttpError>) -> Option<&'
}
parts.as_mut()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_body() {
assert!(Body::Length(10).has_body());
assert!(Body::Streaming.has_body());
}
#[test]
fn test_upgrade() {
let resp = HttpResponse::builder(StatusCode::OK)
.upgrade().body(Body::Empty).unwrap();
assert!(resp.upgrade())
}
#[test]
fn test_force_close() {
let resp = HttpResponse::builder(StatusCode::OK)
.force_close().body(Body::Empty).unwrap();
assert!(!resp.keep_alive().unwrap())
}
#[test]
fn test_content_type() {
let resp = HttpResponse::builder(StatusCode::OK)
.content_type("text/plain").body(Body::Empty).unwrap();
assert_eq!(resp.headers().get(header::CONTENT_TYPE).unwrap(), "text/plain")
}
}