Skip to content

Commit

Permalink
refactor http-test server
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Dec 12, 2019
1 parent db1d6b7 commit 4937c9f
Show file tree
Hide file tree
Showing 17 changed files with 252 additions and 296 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ members = [
]

[features]
default = ["compress", "fail"]
default = ["compress", "failure"]

# content-encoding support
compress = ["actix-http/compress", "awc/compress"]

# sessions feature, session require "ring" crate and c compiler
secure-cookies = ["actix-http/secure-cookies"]

fail = ["actix-http/fail"]
failure = ["actix-http/failure"]

# openssl
openssl = ["actix-tls/openssl", "awc/openssl", "open-ssl"]
Expand Down
6 changes: 3 additions & 3 deletions actix-framed/tests/test_server.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use actix_codec::{AsyncRead, AsyncWrite};
use actix_http::{body, http::StatusCode, ws, Error, HttpService, Response};
use actix_http_test::TestServer;
use actix_http_test::test_server;
use actix_service::{pipeline_factory, IntoServiceFactory, ServiceFactory};
use actix_utils::framed::Dispatcher;
use bytes::Bytes;
Expand Down Expand Up @@ -40,7 +40,7 @@ async fn service(msg: ws::Frame) -> Result<ws::Message, Error> {

#[actix_rt::test]
async fn test_simple() {
let mut srv = TestServer::start(|| {
let mut srv = test_server(|| {
HttpService::build()
.upgrade(
FramedApp::new().service(FramedRoute::get("/index.html").to(ws_service)),
Expand Down Expand Up @@ -94,7 +94,7 @@ async fn test_simple() {

#[actix_rt::test]
async fn test_service() {
let mut srv = TestServer::start(|| {
let mut srv = test_server(|| {
pipeline_factory(actix_http::h1::OneRequest::new().map_err(|_| ())).and_then(
pipeline_factory(
pipeline_factory(VerifyWebSockets::default())
Expand Down
4 changes: 2 additions & 2 deletions actix-http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ rustls = ["actix-tls/rustls", "actix-connect/rustls"]
compress = ["flate2", "brotli"]

# failure integration. actix does not use failure anymore
fail = ["failure"]
failure = ["fail-ure"]

# support for secure cookies
secure-cookies = ["ring"]
Expand Down Expand Up @@ -85,7 +85,7 @@ brotli = { version = "3.3.0", optional = true }
flate2 = { version = "1.0.13", optional = true }

# optional deps
failure = { version = "0.1.5", optional = true }
fail-ure = { version = "0.1.5", package="failure", optional = true }

[dev-dependencies]
actix-server = "1.0.0"
Expand Down
10 changes: 3 additions & 7 deletions actix-http/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -957,13 +957,9 @@ where
InternalError::new(err, StatusCode::NETWORK_AUTHENTICATION_REQUIRED).into()
}

#[cfg(feature = "fail")]
mod failure_integration {
use super::*;

/// Compatibility for `failure::Error`
impl ResponseError for failure::Error {}
}
#[cfg(feature = "failure")]
/// Compatibility for `failure::Error`
impl ResponseError for fail_ure::Error {}

#[cfg(test)]
mod tests {
Expand Down
8 changes: 4 additions & 4 deletions actix-http/tests/test_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use bytes::Bytes;
use futures::future::{self, ok};

use actix_http::{http, HttpService, Request, Response};
use actix_http_test::TestServer;
use actix_http_test::test_server;

const STR: &str = "Hello World Hello World Hello World Hello World Hello World \
Hello World Hello World Hello World Hello World Hello World \
Expand All @@ -29,7 +29,7 @@ const STR: &str = "Hello World Hello World Hello World Hello World Hello World \

#[actix_rt::test]
async fn test_h1_v2() {
let srv = TestServer::start(move || {
let srv = test_server(move || {
HttpService::build()
.finish(|_| future::ok::<_, ()>(Response::Ok().body(STR)))
.tcp()
Expand All @@ -56,7 +56,7 @@ async fn test_h1_v2() {

#[actix_rt::test]
async fn test_connection_close() {
let srv = TestServer::start(move || {
let srv = test_server(move || {
HttpService::build()
.finish(|_| ok::<_, ()>(Response::Ok().body(STR)))
.tcp()
Expand All @@ -69,7 +69,7 @@ async fn test_connection_close() {

#[actix_rt::test]
async fn test_with_query_parameter() {
let srv = TestServer::start(move || {
let srv = test_server(move || {
HttpService::build()
.finish(|req: Request| {
if req.uri().query().unwrap().contains("qp=") {
Expand Down
30 changes: 15 additions & 15 deletions actix-http/tests/test_openssl.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![cfg(feature = "openssl")]
use std::io;

use actix_http_test::TestServer;
use actix_http_test::test_server;
use actix_service::{fn_service, ServiceFactory};

use bytes::{Bytes, BytesMut};
Expand Down Expand Up @@ -62,7 +62,7 @@ fn ssl_acceptor() -> SslAcceptor {

#[actix_rt::test]
async fn test_h2() -> io::Result<()> {
let srv = TestServer::start(move || {
let srv = test_server(move || {
HttpService::build()
.h2(|_| ok::<_, Error>(Response::Ok().finish()))
.openssl(ssl_acceptor())
Expand All @@ -76,7 +76,7 @@ async fn test_h2() -> io::Result<()> {

#[actix_rt::test]
async fn test_h2_1() -> io::Result<()> {
let srv = TestServer::start(move || {
let srv = test_server(move || {
HttpService::build()
.finish(|req: Request| {
assert!(req.peer_addr().is_some());
Expand All @@ -95,7 +95,7 @@ async fn test_h2_1() -> io::Result<()> {
#[actix_rt::test]
async fn test_h2_body() -> io::Result<()> {
let data = "HELLOWORLD".to_owned().repeat(64 * 1024);
let mut srv = TestServer::start(move || {
let mut srv = test_server(move || {
HttpService::build()
.h2(|mut req: Request<_>| {
async move {
Expand All @@ -117,7 +117,7 @@ async fn test_h2_body() -> io::Result<()> {

#[actix_rt::test]
async fn test_h2_content_length() {
let srv = TestServer::start(move || {
let srv = test_server(move || {
HttpService::build()
.h2(|req: Request| {
let indx: usize = req.uri().path()[1..].parse().unwrap();
Expand Down Expand Up @@ -168,7 +168,7 @@ async fn test_h2_headers() {
let data = STR.repeat(10);
let data2 = data.clone();

let mut srv = TestServer::start(move || {
let mut srv = test_server(move || {
let data = data.clone();
HttpService::build().h2(move |_| {
let mut builder = Response::Ok();
Expand Down Expand Up @@ -228,7 +228,7 @@ const STR: &str = "Hello World Hello World Hello World Hello World Hello World \

#[actix_rt::test]
async fn test_h2_body2() {
let mut srv = TestServer::start(move || {
let mut srv = test_server(move || {
HttpService::build()
.h2(|_| ok::<_, ()>(Response::Ok().body(STR)))
.openssl(ssl_acceptor())
Expand All @@ -245,7 +245,7 @@ async fn test_h2_body2() {

#[actix_rt::test]
async fn test_h2_head_empty() {
let mut srv = TestServer::start(move || {
let mut srv = test_server(move || {
HttpService::build()
.finish(|_| ok::<_, ()>(Response::Ok().body(STR)))
.openssl(ssl_acceptor())
Expand All @@ -268,7 +268,7 @@ async fn test_h2_head_empty() {

#[actix_rt::test]
async fn test_h2_head_binary() {
let mut srv = TestServer::start(move || {
let mut srv = test_server(move || {
HttpService::build()
.h2(|_| {
ok::<_, ()>(Response::Ok().content_length(STR.len() as u64).body(STR))
Expand All @@ -292,7 +292,7 @@ async fn test_h2_head_binary() {

#[actix_rt::test]
async fn test_h2_head_binary2() {
let srv = TestServer::start(move || {
let srv = test_server(move || {
HttpService::build()
.h2(|_| ok::<_, ()>(Response::Ok().body(STR)))
.openssl(ssl_acceptor())
Expand All @@ -310,7 +310,7 @@ async fn test_h2_head_binary2() {

#[actix_rt::test]
async fn test_h2_body_length() {
let mut srv = TestServer::start(move || {
let mut srv = test_server(move || {
HttpService::build()
.h2(|_| {
let body = once(ok(Bytes::from_static(STR.as_ref())));
Expand All @@ -332,7 +332,7 @@ async fn test_h2_body_length() {

#[actix_rt::test]
async fn test_h2_body_chunked_explicit() {
let mut srv = TestServer::start(move || {
let mut srv = test_server(move || {
HttpService::build()
.h2(|_| {
let body = once(ok::<_, Error>(Bytes::from_static(STR.as_ref())));
Expand All @@ -359,7 +359,7 @@ async fn test_h2_body_chunked_explicit() {

#[actix_rt::test]
async fn test_h2_response_http_error_handling() {
let mut srv = TestServer::start(move || {
let mut srv = test_server(move || {
HttpService::build()
.h2(fn_service(|_| {
let broken_header = Bytes::from_static(b"\0\0\0");
Expand All @@ -383,7 +383,7 @@ async fn test_h2_response_http_error_handling() {

#[actix_rt::test]
async fn test_h2_service_error() {
let mut srv = TestServer::start(move || {
let mut srv = test_server(move || {
HttpService::build()
.h2(|_| err::<Response, Error>(ErrorBadRequest("error")))
.openssl(ssl_acceptor())
Expand All @@ -400,7 +400,7 @@ async fn test_h2_service_error() {

#[actix_rt::test]
async fn test_h2_on_connect() {
let srv = TestServer::start(move || {
let srv = test_server(move || {
HttpService::build()
.on_connect(|_| 10usize)
.h2(|req: Request| {
Expand Down
Loading

0 comments on commit 4937c9f

Please sign in to comment.