1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-28 01:52:57 +01:00

update tests

This commit is contained in:
Nikolay Kim 2019-02-18 18:46:30 -08:00
parent 037c3da172
commit d180b2a1e3
4 changed files with 29 additions and 28 deletions

View File

@ -53,7 +53,7 @@ pub struct TestServerRuntime<T> {
impl TestServer { impl TestServer {
/// Start new test server with application factory /// Start new test server with application factory
pub fn with_factory<F: StreamServiceFactory>( pub fn new<F: StreamServiceFactory>(
factory: F, factory: F,
) -> TestServerRuntime< ) -> TestServerRuntime<
impl Service<Request = Connect, Response = impl Connection, Error = ConnectorError> impl Service<Request = Connect, Response = impl Connection, Error = ConnectorError>

View File

@ -31,7 +31,7 @@ const STR: &str = "Hello World Hello World Hello World Hello World Hello World \
#[test] #[test]
fn test_h1_v2() { fn test_h1_v2() {
env_logger::init(); env_logger::init();
let mut srv = TestServer::with_factory(move || { let mut srv = TestServer::new(move || {
h1::H1Service::build() h1::H1Service::build()
.finish(|_| future::ok::<_, ()>(Response::Ok().body(STR))) .finish(|_| future::ok::<_, ()>(Response::Ok().body(STR)))
.map(|_| ()) .map(|_| ())
@ -65,7 +65,7 @@ fn test_h1_v2() {
#[test] #[test]
fn test_connection_close() { fn test_connection_close() {
let mut srv = TestServer::with_factory(move || { let mut srv = TestServer::new(move || {
h1::H1Service::build() h1::H1Service::build()
.finish(|_| ok::<_, ()>(Response::Ok().body(STR))) .finish(|_| ok::<_, ()>(Response::Ok().body(STR)))
.map(|_| ()) .map(|_| ())
@ -79,7 +79,7 @@ fn test_connection_close() {
#[test] #[test]
fn test_with_query_parameter() { fn test_with_query_parameter() {
let mut srv = TestServer::with_factory(move || { let mut srv = TestServer::new(move || {
h1::H1Service::build() h1::H1Service::build()
.finish(|req: Request| { .finish(|req: Request| {
if req.uri().query().unwrap().contains("qp=") { if req.uri().query().unwrap().contains("qp=") {

View File

@ -8,14 +8,15 @@ use bytes::Bytes;
use futures::future::{self, ok, Future}; use futures::future::{self, ok, Future};
use futures::stream::once; use futures::stream::once;
use actix_http::body::Body;
use actix_http::{ use actix_http::{
body, client, h1, h2, http, Body, Error, HttpMessage as HttpMessage2, KeepAlive, body, client, h1, h2, http, Error, HttpMessage as HttpMessage2, KeepAlive, Request,
Request, Response, Response,
}; };
#[test] #[test]
fn test_h1() { fn test_h1() {
let mut srv = TestServer::with_factory(|| { let mut srv = TestServer::new(|| {
h1::H1Service::build() h1::H1Service::build()
.keep_alive(KeepAlive::Disabled) .keep_alive(KeepAlive::Disabled)
.client_timeout(1000) .client_timeout(1000)
@ -57,7 +58,7 @@ fn ssl_acceptor<T>() -> std::io::Result<actix_server::ssl::OpensslAcceptor<T>> {
#[test] #[test]
fn test_h2() -> std::io::Result<()> { fn test_h2() -> std::io::Result<()> {
let openssl = ssl_acceptor()?; let openssl = ssl_acceptor()?;
let mut srv = TestServer::with_factory(move || { let mut srv = TestServer::new(move || {
openssl openssl
.clone() .clone()
.map_err(|e| println!("Openssl error: {}", e)) .map_err(|e| println!("Openssl error: {}", e))
@ -83,7 +84,7 @@ fn test_h2_body() -> std::io::Result<()> {
let data = "HELLOWORLD".to_owned().repeat(64 * 1024); let data = "HELLOWORLD".to_owned().repeat(64 * 1024);
let openssl = ssl_acceptor()?; let openssl = ssl_acceptor()?;
let mut srv = TestServer::with_factory(move || { let mut srv = TestServer::new(move || {
openssl openssl
.clone() .clone()
.map_err(|e| println!("Openssl error: {}", e)) .map_err(|e| println!("Openssl error: {}", e))
@ -111,7 +112,7 @@ fn test_h2_body() -> std::io::Result<()> {
#[test] #[test]
fn test_slow_request() { fn test_slow_request() {
let srv = TestServer::with_factory(|| { let srv = TestServer::new(|| {
h1::H1Service::build() h1::H1Service::build()
.client_timeout(100) .client_timeout(100)
.finish(|_| future::ok::<_, ()>(Response::Ok().finish())) .finish(|_| future::ok::<_, ()>(Response::Ok().finish()))
@ -127,7 +128,7 @@ fn test_slow_request() {
#[test] #[test]
fn test_malformed_request() { fn test_malformed_request() {
let srv = TestServer::with_factory(|| { let srv = TestServer::new(|| {
h1::H1Service::new(|_| future::ok::<_, ()>(Response::Ok().finish())).map(|_| ()) h1::H1Service::new(|_| future::ok::<_, ()>(Response::Ok().finish())).map(|_| ())
}); });
@ -140,7 +141,7 @@ fn test_malformed_request() {
#[test] #[test]
fn test_keepalive() { fn test_keepalive() {
let srv = TestServer::with_factory(|| { let srv = TestServer::new(|| {
h1::H1Service::build() h1::H1Service::build()
.finish(|_| future::ok::<_, ()>(Response::Ok().finish())) .finish(|_| future::ok::<_, ()>(Response::Ok().finish()))
.map(|_| ()) .map(|_| ())
@ -160,7 +161,7 @@ fn test_keepalive() {
#[test] #[test]
fn test_keepalive_timeout() { fn test_keepalive_timeout() {
let srv = TestServer::with_factory(|| { let srv = TestServer::new(|| {
h1::H1Service::build() h1::H1Service::build()
.keep_alive(1) .keep_alive(1)
.finish(|_| future::ok::<_, ()>(Response::Ok().finish())) .finish(|_| future::ok::<_, ()>(Response::Ok().finish()))
@ -181,7 +182,7 @@ fn test_keepalive_timeout() {
#[test] #[test]
fn test_keepalive_close() { fn test_keepalive_close() {
let srv = TestServer::with_factory(|| { let srv = TestServer::new(|| {
h1::H1Service::build() h1::H1Service::build()
.finish(|_| future::ok::<_, ()>(Response::Ok().finish())) .finish(|_| future::ok::<_, ()>(Response::Ok().finish()))
.map(|_| ()) .map(|_| ())
@ -201,7 +202,7 @@ fn test_keepalive_close() {
#[test] #[test]
fn test_keepalive_http10_default_close() { fn test_keepalive_http10_default_close() {
let srv = TestServer::with_factory(|| { let srv = TestServer::new(|| {
h1::H1Service::build() h1::H1Service::build()
.finish(|_| future::ok::<_, ()>(Response::Ok().finish())) .finish(|_| future::ok::<_, ()>(Response::Ok().finish()))
.map(|_| ()) .map(|_| ())
@ -220,7 +221,7 @@ fn test_keepalive_http10_default_close() {
#[test] #[test]
fn test_keepalive_http10() { fn test_keepalive_http10() {
let srv = TestServer::with_factory(|| { let srv = TestServer::new(|| {
h1::H1Service::build() h1::H1Service::build()
.finish(|_| future::ok::<_, ()>(Response::Ok().finish())) .finish(|_| future::ok::<_, ()>(Response::Ok().finish()))
.map(|_| ()) .map(|_| ())
@ -246,7 +247,7 @@ fn test_keepalive_http10() {
#[test] #[test]
fn test_keepalive_disabled() { fn test_keepalive_disabled() {
let srv = TestServer::with_factory(|| { let srv = TestServer::new(|| {
h1::H1Service::build() h1::H1Service::build()
.keep_alive(KeepAlive::Disabled) .keep_alive(KeepAlive::Disabled)
.finish(|_| future::ok::<_, ()>(Response::Ok().finish())) .finish(|_| future::ok::<_, ()>(Response::Ok().finish()))
@ -271,7 +272,7 @@ fn test_content_length() {
StatusCode, StatusCode,
}; };
let mut srv = TestServer::with_factory(|| { let mut srv = TestServer::new(|| {
h1::H1Service::new(|req: Request| { h1::H1Service::new(|req: Request| {
let indx: usize = req.uri().path()[1..].parse().unwrap(); let indx: usize = req.uri().path()[1..].parse().unwrap();
let statuses = [ let statuses = [
@ -320,7 +321,7 @@ fn test_headers() {
let data = STR.repeat(10); let data = STR.repeat(10);
let data2 = data.clone(); let data2 = data.clone();
let mut srv = TestServer::with_factory(move || { let mut srv = TestServer::new(move || {
let data = data.clone(); let data = data.clone();
h1::H1Service::new(move |_| { h1::H1Service::new(move |_| {
let mut builder = Response::Ok(); let mut builder = Response::Ok();
@ -382,7 +383,7 @@ const STR: &str = "Hello World Hello World Hello World Hello World Hello World \
#[test] #[test]
fn test_body() { fn test_body() {
let mut srv = TestServer::with_factory(|| { let mut srv = TestServer::new(|| {
h1::H1Service::new(|_| future::ok::<_, ()>(Response::Ok().body(STR))).map(|_| ()) h1::H1Service::new(|_| future::ok::<_, ()>(Response::Ok().body(STR))).map(|_| ())
}); });
@ -397,7 +398,7 @@ fn test_body() {
#[test] #[test]
fn test_head_empty() { fn test_head_empty() {
let mut srv = TestServer::with_factory(|| { let mut srv = TestServer::new(|| {
h1::H1Service::new(|_| ok::<_, ()>(Response::Ok().body(STR))).map(|_| ()) h1::H1Service::new(|_| ok::<_, ()>(Response::Ok().body(STR))).map(|_| ())
}); });
@ -420,7 +421,7 @@ fn test_head_empty() {
#[test] #[test]
fn test_head_binary() { fn test_head_binary() {
let mut srv = TestServer::with_factory(|| { let mut srv = TestServer::new(|| {
h1::H1Service::new(|_| { h1::H1Service::new(|_| {
ok::<_, ()>(Response::Ok().content_length(STR.len() as u64).body(STR)) ok::<_, ()>(Response::Ok().content_length(STR.len() as u64).body(STR))
}) })
@ -446,7 +447,7 @@ fn test_head_binary() {
#[test] #[test]
fn test_head_binary2() { fn test_head_binary2() {
let mut srv = TestServer::with_factory(|| { let mut srv = TestServer::new(|| {
h1::H1Service::new(|_| ok::<_, ()>(Response::Ok().body(STR))).map(|_| ()) h1::H1Service::new(|_| ok::<_, ()>(Response::Ok().body(STR))).map(|_| ())
}); });
@ -465,7 +466,7 @@ fn test_head_binary2() {
#[test] #[test]
fn test_body_length() { fn test_body_length() {
let mut srv = TestServer::with_factory(|| { let mut srv = TestServer::new(|| {
h1::H1Service::new(|_| { h1::H1Service::new(|_| {
let body = once(Ok(Bytes::from_static(STR.as_ref()))); let body = once(Ok(Bytes::from_static(STR.as_ref())));
ok::<_, ()>( ok::<_, ()>(
@ -487,7 +488,7 @@ fn test_body_length() {
#[test] #[test]
fn test_body_chunked_explicit() { fn test_body_chunked_explicit() {
let mut srv = TestServer::with_factory(|| { let mut srv = TestServer::new(|| {
h1::H1Service::new(|_| { h1::H1Service::new(|_| {
let body = once::<_, Error>(Ok(Bytes::from_static(STR.as_ref()))); let body = once::<_, Error>(Ok(Bytes::from_static(STR.as_ref())));
ok::<_, ()>(Response::Ok().streaming(body)) ok::<_, ()>(Response::Ok().streaming(body))
@ -508,7 +509,7 @@ fn test_body_chunked_explicit() {
#[test] #[test]
fn test_body_chunked_implicit() { fn test_body_chunked_implicit() {
let mut srv = TestServer::with_factory(|| { let mut srv = TestServer::new(|| {
h1::H1Service::new(|_| { h1::H1Service::new(|_| {
let body = once::<_, Error>(Ok(Bytes::from_static(STR.as_ref()))); let body = once::<_, Error>(Ok(Bytes::from_static(STR.as_ref())));
ok::<_, ()>(Response::Ok().streaming(body)) ok::<_, ()>(Response::Ok().streaming(body))
@ -527,7 +528,7 @@ fn test_body_chunked_implicit() {
#[test] #[test]
fn test_response_http_error_handling() { fn test_response_http_error_handling() {
let mut srv = TestServer::with_factory(|| { let mut srv = TestServer::new(|| {
h1::H1Service::new(|_| { h1::H1Service::new(|_| {
let broken_header = Bytes::from_static(b"\0\0\0"); let broken_header = Bytes::from_static(b"\0\0\0");
ok::<_, ()>( ok::<_, ()>(

View File

@ -34,7 +34,7 @@ fn ws_service(req: ws::Frame) -> impl Future<Item = ws::Message, Error = io::Err
#[test] #[test]
fn test_simple() { fn test_simple() {
let mut srv = TestServer::with_factory(|| { let mut srv = TestServer::new(|| {
IntoFramed::new(|| h1::Codec::new(ServiceConfig::default())) IntoFramed::new(|| h1::Codec::new(ServiceConfig::default()))
.and_then(TakeItem::new().map_err(|_| ())) .and_then(TakeItem::new().map_err(|_| ()))
.and_then(|(req, framed): (_, Framed<_, _>)| { .and_then(|(req, framed): (_, Framed<_, _>)| {