mirror of
https://github.com/actix/actix-web.git
synced 2024-11-20 08:31:09 +00:00
update tests
This commit is contained in:
parent
3a954298d7
commit
193f8fb2d9
7 changed files with 74 additions and 63 deletions
|
@ -96,8 +96,9 @@ openssl = { version="0.10", optional = true }
|
|||
|
||||
[dev-dependencies]
|
||||
actix-rt = "0.2.2"
|
||||
actix-server = { version = "0.4.0", features=["ssl"] }
|
||||
actix-server = { version = "0.4.1", features=["ssl"] }
|
||||
actix-connect = { version = "0.1.0", features=["ssl"] }
|
||||
#actix-http-test = { version = "0.1.0-alpha.1", features=["ssl"] }
|
||||
actix-http-test = { path = "../test-server", features=["ssl"] }
|
||||
|
||||
env_logger = "0.6"
|
||||
|
|
|
@ -52,18 +52,18 @@ fn test_h1_v2() {
|
|||
assert!(response.status().is_success());
|
||||
|
||||
let request = srv.get().header("x-test", "111").send();
|
||||
let mut response = srv.block_on(request).unwrap();
|
||||
let response = srv.block_on(request).unwrap();
|
||||
assert!(response.status().is_success());
|
||||
|
||||
// read response
|
||||
let bytes = srv.block_on(load_body(response.take_payload())).unwrap();
|
||||
let bytes = srv.load_body(response).unwrap();
|
||||
assert_eq!(bytes, Bytes::from_static(STR.as_ref()));
|
||||
|
||||
let mut response = srv.block_on(srv.post().send()).unwrap();
|
||||
let response = srv.block_on(srv.post().send()).unwrap();
|
||||
assert!(response.status().is_success());
|
||||
|
||||
// read response
|
||||
let bytes = srv.block_on(load_body(response.take_payload())).unwrap();
|
||||
let bytes = srv.load_body(response).unwrap();
|
||||
assert_eq!(bytes, Bytes::from_static(STR.as_ref()));
|
||||
}
|
||||
|
||||
|
|
|
@ -13,8 +13,7 @@ use futures::stream::{once, Stream};
|
|||
use actix_http::body::Body;
|
||||
use actix_http::error::PayloadError;
|
||||
use actix_http::{
|
||||
body, error, http, http::header, Error, HttpMessage, HttpService, KeepAlive,
|
||||
Request, Response,
|
||||
body, error, http, http::header, Error, HttpService, KeepAlive, Request, Response,
|
||||
};
|
||||
|
||||
fn load_body<S>(stream: S) -> impl Future<Item = BytesMut, Error = PayloadError>
|
||||
|
@ -145,10 +144,10 @@ fn test_h2_body() -> std::io::Result<()> {
|
|||
)
|
||||
});
|
||||
|
||||
let mut response = srv.block_on(srv.sget().send_body(data.clone())).unwrap();
|
||||
let response = srv.block_on(srv.sget().send_body(data.clone())).unwrap();
|
||||
assert!(response.status().is_success());
|
||||
|
||||
let body = srv.block_on(load_body(response.take_payload())).unwrap();
|
||||
let body = srv.load_body(response).unwrap();
|
||||
assert_eq!(&body, data.as_bytes());
|
||||
Ok(())
|
||||
}
|
||||
|
@ -436,11 +435,11 @@ fn test_h1_headers() {
|
|||
})
|
||||
});
|
||||
|
||||
let mut response = srv.block_on(srv.get().send()).unwrap();
|
||||
let response = srv.block_on(srv.get().send()).unwrap();
|
||||
assert!(response.status().is_success());
|
||||
|
||||
// read response
|
||||
let bytes = srv.block_on(load_body(response.take_payload())).unwrap();
|
||||
let bytes = srv.load_body(response).unwrap();
|
||||
assert_eq!(bytes, Bytes::from(data2));
|
||||
}
|
||||
|
||||
|
@ -480,11 +479,11 @@ fn test_h2_headers() {
|
|||
}).map_err(|_| ()))
|
||||
});
|
||||
|
||||
let mut response = srv.block_on(srv.sget().send()).unwrap();
|
||||
let response = srv.block_on(srv.sget().send()).unwrap();
|
||||
assert!(response.status().is_success());
|
||||
|
||||
// read response
|
||||
let bytes = srv.block_on(load_body(response.take_payload())).unwrap();
|
||||
let bytes = srv.load_body(response).unwrap();
|
||||
assert_eq!(bytes, Bytes::from(data2));
|
||||
}
|
||||
|
||||
|
@ -516,11 +515,11 @@ fn test_h1_body() {
|
|||
HttpService::build().h1(|_| future::ok::<_, ()>(Response::Ok().body(STR)))
|
||||
});
|
||||
|
||||
let mut response = srv.block_on(srv.get().send()).unwrap();
|
||||
let response = srv.block_on(srv.get().send()).unwrap();
|
||||
assert!(response.status().is_success());
|
||||
|
||||
// read response
|
||||
let bytes = srv.block_on(load_body(response.take_payload())).unwrap();
|
||||
let bytes = srv.load_body(response).unwrap();
|
||||
assert_eq!(bytes, Bytes::from_static(STR.as_ref()));
|
||||
}
|
||||
|
||||
|
@ -538,11 +537,11 @@ fn test_h2_body2() {
|
|||
)
|
||||
});
|
||||
|
||||
let mut response = srv.block_on(srv.sget().send()).unwrap();
|
||||
let response = srv.block_on(srv.sget().send()).unwrap();
|
||||
assert!(response.status().is_success());
|
||||
|
||||
// read response
|
||||
let bytes = srv.block_on(load_body(response.take_payload())).unwrap();
|
||||
let bytes = srv.load_body(response).unwrap();
|
||||
assert_eq!(bytes, Bytes::from_static(STR.as_ref()));
|
||||
}
|
||||
|
||||
|
@ -552,7 +551,7 @@ fn test_h1_head_empty() {
|
|||
HttpService::build().h1(|_| ok::<_, ()>(Response::Ok().body(STR)))
|
||||
});
|
||||
|
||||
let mut response = srv.block_on(srv.head().send()).unwrap();
|
||||
let response = srv.block_on(srv.head().send()).unwrap();
|
||||
assert!(response.status().is_success());
|
||||
|
||||
{
|
||||
|
@ -564,7 +563,7 @@ fn test_h1_head_empty() {
|
|||
}
|
||||
|
||||
// read response
|
||||
let bytes = srv.block_on(load_body(response.take_payload())).unwrap();
|
||||
let bytes = srv.load_body(response).unwrap();
|
||||
assert!(bytes.is_empty());
|
||||
}
|
||||
|
||||
|
@ -582,7 +581,7 @@ fn test_h2_head_empty() {
|
|||
)
|
||||
});
|
||||
|
||||
let mut response = srv.block_on(srv.shead().send()).unwrap();
|
||||
let response = srv.block_on(srv.shead().send()).unwrap();
|
||||
assert!(response.status().is_success());
|
||||
assert_eq!(response.version(), http::Version::HTTP_2);
|
||||
|
||||
|
@ -595,7 +594,7 @@ fn test_h2_head_empty() {
|
|||
}
|
||||
|
||||
// read response
|
||||
let bytes = srv.block_on(load_body(response.take_payload())).unwrap();
|
||||
let bytes = srv.load_body(response).unwrap();
|
||||
assert!(bytes.is_empty());
|
||||
}
|
||||
|
||||
|
@ -607,7 +606,7 @@ fn test_h1_head_binary() {
|
|||
})
|
||||
});
|
||||
|
||||
let mut response = srv.block_on(srv.head().send()).unwrap();
|
||||
let response = srv.block_on(srv.head().send()).unwrap();
|
||||
assert!(response.status().is_success());
|
||||
|
||||
{
|
||||
|
@ -619,7 +618,7 @@ fn test_h1_head_binary() {
|
|||
}
|
||||
|
||||
// read response
|
||||
let bytes = srv.block_on(load_body(response.take_payload())).unwrap();
|
||||
let bytes = srv.load_body(response).unwrap();
|
||||
assert!(bytes.is_empty());
|
||||
}
|
||||
|
||||
|
@ -641,7 +640,7 @@ fn test_h2_head_binary() {
|
|||
)
|
||||
});
|
||||
|
||||
let mut response = srv.block_on(srv.shead().send()).unwrap();
|
||||
let response = srv.block_on(srv.shead().send()).unwrap();
|
||||
assert!(response.status().is_success());
|
||||
|
||||
{
|
||||
|
@ -653,7 +652,7 @@ fn test_h2_head_binary() {
|
|||
}
|
||||
|
||||
// read response
|
||||
let bytes = srv.block_on(load_body(response.take_payload())).unwrap();
|
||||
let bytes = srv.load_body(response).unwrap();
|
||||
assert!(bytes.is_empty());
|
||||
}
|
||||
|
||||
|
@ -713,11 +712,11 @@ fn test_h1_body_length() {
|
|||
})
|
||||
});
|
||||
|
||||
let mut response = srv.block_on(srv.get().send()).unwrap();
|
||||
let response = srv.block_on(srv.get().send()).unwrap();
|
||||
assert!(response.status().is_success());
|
||||
|
||||
// read response
|
||||
let bytes = srv.block_on(load_body(response.take_payload())).unwrap();
|
||||
let bytes = srv.load_body(response).unwrap();
|
||||
assert_eq!(bytes, Bytes::from_static(STR.as_ref()));
|
||||
}
|
||||
|
||||
|
@ -740,11 +739,11 @@ fn test_h2_body_length() {
|
|||
)
|
||||
});
|
||||
|
||||
let mut response = srv.block_on(srv.sget().send()).unwrap();
|
||||
let response = srv.block_on(srv.sget().send()).unwrap();
|
||||
assert!(response.status().is_success());
|
||||
|
||||
// read response
|
||||
let bytes = srv.block_on(load_body(response.take_payload())).unwrap();
|
||||
let bytes = srv.load_body(response).unwrap();
|
||||
assert_eq!(bytes, Bytes::from_static(STR.as_ref()));
|
||||
}
|
||||
|
||||
|
@ -761,7 +760,7 @@ fn test_h1_body_chunked_explicit() {
|
|||
})
|
||||
});
|
||||
|
||||
let mut response = srv.block_on(srv.get().send()).unwrap();
|
||||
let response = srv.block_on(srv.get().send()).unwrap();
|
||||
assert!(response.status().is_success());
|
||||
assert_eq!(
|
||||
response
|
||||
|
@ -774,7 +773,7 @@ fn test_h1_body_chunked_explicit() {
|
|||
);
|
||||
|
||||
// read response
|
||||
let bytes = srv.block_on(load_body(response.take_payload())).unwrap();
|
||||
let bytes = srv.load_body(response).unwrap();
|
||||
|
||||
// decode
|
||||
assert_eq!(bytes, Bytes::from_static(STR.as_ref()));
|
||||
|
@ -802,12 +801,12 @@ fn test_h2_body_chunked_explicit() {
|
|||
)
|
||||
});
|
||||
|
||||
let mut response = srv.block_on(srv.sget().send()).unwrap();
|
||||
let response = srv.block_on(srv.sget().send()).unwrap();
|
||||
assert!(response.status().is_success());
|
||||
assert!(!response.headers().contains_key(header::TRANSFER_ENCODING));
|
||||
|
||||
// read response
|
||||
let bytes = srv.block_on(load_body(response.take_payload())).unwrap();
|
||||
let bytes = srv.load_body(response).unwrap();
|
||||
|
||||
// decode
|
||||
assert_eq!(bytes, Bytes::from_static(STR.as_ref()));
|
||||
|
@ -822,7 +821,7 @@ fn test_h1_body_chunked_implicit() {
|
|||
})
|
||||
});
|
||||
|
||||
let mut response = srv.block_on(srv.get().send()).unwrap();
|
||||
let response = srv.block_on(srv.get().send()).unwrap();
|
||||
assert!(response.status().is_success());
|
||||
assert_eq!(
|
||||
response
|
||||
|
@ -835,7 +834,7 @@ fn test_h1_body_chunked_implicit() {
|
|||
);
|
||||
|
||||
// read response
|
||||
let bytes = srv.block_on(load_body(response.take_payload())).unwrap();
|
||||
let bytes = srv.load_body(response).unwrap();
|
||||
assert_eq!(bytes, Bytes::from_static(STR.as_ref()));
|
||||
}
|
||||
|
||||
|
@ -854,11 +853,11 @@ fn test_h1_response_http_error_handling() {
|
|||
}))
|
||||
});
|
||||
|
||||
let mut response = srv.block_on(srv.get().send()).unwrap();
|
||||
let response = srv.block_on(srv.get().send()).unwrap();
|
||||
assert_eq!(response.status(), http::StatusCode::INTERNAL_SERVER_ERROR);
|
||||
|
||||
// read response
|
||||
let bytes = srv.block_on(load_body(response.take_payload())).unwrap();
|
||||
let bytes = srv.load_body(response).unwrap();
|
||||
assert!(bytes.is_empty());
|
||||
}
|
||||
|
||||
|
@ -886,11 +885,11 @@ fn test_h2_response_http_error_handling() {
|
|||
)
|
||||
});
|
||||
|
||||
let mut response = srv.block_on(srv.sget().send()).unwrap();
|
||||
let response = srv.block_on(srv.sget().send()).unwrap();
|
||||
assert_eq!(response.status(), http::StatusCode::INTERNAL_SERVER_ERROR);
|
||||
|
||||
// read response
|
||||
let bytes = srv.block_on(load_body(response.take_payload())).unwrap();
|
||||
let bytes = srv.load_body(response).unwrap();
|
||||
assert!(bytes.is_empty());
|
||||
}
|
||||
|
||||
|
@ -901,11 +900,11 @@ fn test_h1_service_error() {
|
|||
.h1(|_| Err::<Response, Error>(error::ErrorBadRequest("error")))
|
||||
});
|
||||
|
||||
let mut response = srv.block_on(srv.get().send()).unwrap();
|
||||
let response = srv.block_on(srv.get().send()).unwrap();
|
||||
assert_eq!(response.status(), http::StatusCode::INTERNAL_SERVER_ERROR);
|
||||
|
||||
// read response
|
||||
let bytes = srv.block_on(load_body(response.take_payload())).unwrap();
|
||||
let bytes = srv.load_body(response).unwrap();
|
||||
assert!(bytes.is_empty());
|
||||
}
|
||||
|
||||
|
@ -924,10 +923,10 @@ fn test_h2_service_error() {
|
|||
)
|
||||
});
|
||||
|
||||
let mut response = srv.block_on(srv.sget().send()).unwrap();
|
||||
let response = srv.block_on(srv.sget().send()).unwrap();
|
||||
assert_eq!(response.status(), http::StatusCode::INTERNAL_SERVER_ERROR);
|
||||
|
||||
// read response
|
||||
let bytes = srv.block_on(load_body(response.take_payload())).unwrap();
|
||||
let bytes = srv.load_body(response).unwrap();
|
||||
assert!(bytes.is_empty());
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ use cookie::{Cookie, CookieJar};
|
|||
use futures::future::{err, Either, Future};
|
||||
use tokio_timer::Timeout;
|
||||
|
||||
pub use actix_http::ws::{CloseCode, CloseReason, Frame, Message};
|
||||
pub use actix_http::ws::{CloseCode, CloseReason, Codec, Frame, Message};
|
||||
|
||||
use crate::connect::BoxedSocket;
|
||||
use crate::error::{InvalidUrl, SendRequestError, WsClientError};
|
||||
|
@ -213,10 +213,8 @@ impl WebsocketsRequest {
|
|||
/// Complete request construction and connect to a websockets server.
|
||||
pub fn connect(
|
||||
mut self,
|
||||
) -> impl Future<
|
||||
Item = (ClientResponse, Framed<BoxedSocket, ws::Codec>),
|
||||
Error = WsClientError,
|
||||
> {
|
||||
) -> impl Future<Item = (ClientResponse, Framed<BoxedSocket, Codec>), Error = WsClientError>
|
||||
{
|
||||
if let Some(e) = self.err.take() {
|
||||
return Either::A(err(e.into()));
|
||||
}
|
||||
|
|
|
@ -30,12 +30,11 @@ default = ["session"]
|
|||
session = ["cookie/secure"]
|
||||
|
||||
# openssl
|
||||
ssl = ["openssl", "actix-http/ssl", "actix-server/ssl", "awc/ssl"]
|
||||
ssl = ["openssl", "actix-server/ssl", "awc/ssl"]
|
||||
|
||||
[dependencies]
|
||||
actix-codec = "0.1.1"
|
||||
actix-rt = "0.2.1"
|
||||
actix-http = { path = "../actix-http" }
|
||||
actix-service = "0.3.4"
|
||||
actix-server = "0.4.0"
|
||||
actix-utils = "0.3.4"
|
||||
|
@ -61,4 +60,4 @@ tokio-timer = "0.2"
|
|||
openssl = { version="0.10", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
actix-web = { path = ".." }
|
||||
actix-web = "1.0.0-alpha.1"
|
||||
|
|
|
@ -3,12 +3,12 @@ use std::sync::mpsc;
|
|||
use std::{net, thread, time};
|
||||
|
||||
use actix_codec::{AsyncRead, AsyncWrite, Framed};
|
||||
use actix_http::client::Connector;
|
||||
use actix_http::ws;
|
||||
use actix_rt::{Runtime, System};
|
||||
use actix_server::{Server, StreamServiceFactory};
|
||||
use awc::{Client, ClientRequest};
|
||||
use futures::future::{lazy, Future};
|
||||
use awc::{error::PayloadError, ws, Client, ClientRequest, ClientResponse, Connector};
|
||||
use bytes::Bytes;
|
||||
use futures::future::lazy;
|
||||
use futures::{Future, Stream};
|
||||
use http::Method;
|
||||
use net2::TcpBuilder;
|
||||
|
||||
|
@ -193,13 +193,16 @@ impl TestServerRuntime {
|
|||
self.client.request(method, path.as_ref())
|
||||
}
|
||||
|
||||
/// Stop http server
|
||||
fn stop(&mut self) {
|
||||
System::current().stop();
|
||||
pub fn load_body<S>(
|
||||
&mut self,
|
||||
response: ClientResponse<S>,
|
||||
) -> Result<Bytes, PayloadError>
|
||||
where
|
||||
S: Stream<Item = Bytes, Error = PayloadError> + 'static,
|
||||
{
|
||||
self.block_on(response.body().limit(10_485_760))
|
||||
}
|
||||
}
|
||||
|
||||
impl TestServerRuntime {
|
||||
/// Connect to websocket server at a given path
|
||||
pub fn ws_at(
|
||||
&mut self,
|
||||
|
@ -219,6 +222,11 @@ impl TestServerRuntime {
|
|||
{
|
||||
self.ws_at("/")
|
||||
}
|
||||
|
||||
/// Stop http server
|
||||
fn stop(&mut self) {
|
||||
System::current().stop();
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for TestServerRuntime {
|
||||
|
|
|
@ -100,7 +100,8 @@ fn test_body_encoding_override() {
|
|||
.service(web::resource("/raw").route(web::to(|| {
|
||||
use actix_web::middleware::encoding::BodyEncoding;
|
||||
let body = actix_web::dev::Body::Bytes(STR.into());
|
||||
let mut response = Response::with_body(actix_web::http::StatusCode::OK, body);
|
||||
let mut response =
|
||||
Response::with_body(actix_web::http::StatusCode::OK, body);
|
||||
|
||||
response.encoding(ContentEncoding::Deflate);
|
||||
|
||||
|
@ -123,7 +124,13 @@ fn test_body_encoding_override() {
|
|||
assert_eq!(Bytes::from(dec), Bytes::from_static(STR.as_ref()));
|
||||
|
||||
// Raw Response
|
||||
let mut response = srv.block_on(srv.request(actix_web::http::Method::GET, srv.url("/raw")).no_decompress().send()).unwrap();
|
||||
let mut response = srv
|
||||
.block_on(
|
||||
srv.request(actix_web::http::Method::GET, srv.url("/raw"))
|
||||
.no_decompress()
|
||||
.send(),
|
||||
)
|
||||
.unwrap();
|
||||
assert!(response.status().is_success());
|
||||
|
||||
// read response
|
||||
|
@ -134,7 +141,6 @@ fn test_body_encoding_override() {
|
|||
e.write_all(bytes.as_ref()).unwrap();
|
||||
let dec = e.finish().unwrap();
|
||||
assert_eq!(Bytes::from(dec), Bytes::from_static(STR.as_ref()));
|
||||
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))]
|
||||
|
|
Loading…
Reference in a new issue