From 878f32c4950247d49b9ffeb63385e4a133ee750c Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Thu, 28 Mar 2019 14:27:07 -0700 Subject: [PATCH] fix tests for no-default-features --- .travis.yml | 3 ++- src/app.rs | 1 + tests/test_httpserver.rs | 41 ++++++++++++++++++++++------------------ tests/test_server.rs | 24 ++++++++++++++++++++--- 4 files changed, 47 insertions(+), 22 deletions(-) diff --git a/.travis.yml b/.travis.yml index 061c8b8e7..7f61201f6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,7 +34,8 @@ before_script: - export PATH=$PATH:~/.cargo/bin script: - - cargo clean + - cargo update + - cargo check --all --no-default-features - cargo test --all-features --all -- --nocapture # Upload docs diff --git a/src/app.rs b/src/app.rs index 0daa54b66..a6dfdd554 100644 --- a/src/app.rs +++ b/src/app.rs @@ -10,6 +10,7 @@ use actix_service::boxed::{self, BoxedNewService}; use actix_service::{ ApplyTransform, IntoNewService, IntoTransform, NewService, Transform, }; +#[cfg(any(feature = "brotli", feature = "flate2-zlib", feature = "flate2-rust"))] use bytes::Bytes; use futures::{IntoFuture, Stream}; diff --git a/tests/test_httpserver.rs b/tests/test_httpserver.rs index 4a3850f13..bafe578e9 100644 --- a/tests/test_httpserver.rs +++ b/tests/test_httpserver.rs @@ -2,9 +2,8 @@ use net2::TcpBuilder; use std::sync::mpsc; use std::{net, thread, time::Duration}; -use actix_http::{client, Response}; - -use actix_web::{test, web, App, HttpServer}; +use actix_http::Response; +use actix_web::{web, App, HttpServer}; fn unused_addr() -> net::SocketAddr { let addr: net::SocketAddr = "127.0.0.1:0".parse().unwrap(); @@ -48,22 +47,28 @@ fn test_start() { }); let (srv, sys) = rx.recv().unwrap(); - let client = test::run_on(|| { - Ok::<_, ()>( - awc::Client::build() - .connector( - client::Connector::new() - .timeout(Duration::from_millis(100)) - .service(), - ) - .finish(), - ) - }) - .unwrap(); - let host = format!("http://{}", addr); + #[cfg(feature = "client")] + { + use actix_http::client; + use actix_web::test; - let response = test::block_on(client.get(host.clone()).send()).unwrap(); - assert!(response.status().is_success()); + let client = test::run_on(|| { + Ok::<_, ()>( + awc::Client::build() + .connector( + client::Connector::new() + .timeout(Duration::from_millis(100)) + .service(), + ) + .finish(), + ) + }) + .unwrap(); + let host = format!("http://{}", addr); + + let response = test::block_on(client.get(host.clone()).send()).unwrap(); + assert!(response.status().is_success()); + } // stop let _ = srv.stop(false); diff --git a/tests/test_server.rs b/tests/test_server.rs index c30cf67f8..cd5e95d20 100644 --- a/tests/test_server.rs +++ b/tests/test_server.rs @@ -11,10 +11,13 @@ use bytes::Bytes; use flate2::read::GzDecoder; use flate2::write::{GzEncoder, ZlibDecoder, ZlibEncoder}; use flate2::Compression; -use futures::stream::once; //Future, Stream +use futures::stream::once; use rand::{distributions::Alphanumeric, Rng}; -use actix_web::{dev::HttpMessageBody, middleware::encoding, web, App}; +use actix_web::{dev::HttpMessageBody, web, App}; + +#[cfg(any(feature = "brotli", feature = "flate2-zlib", feature = "flate2-rust"))] +use actix_web::middleware::encoding; const STR: &str = "Hello World Hello World Hello World Hello World Hello World \ Hello World Hello World Hello World Hello World Hello World \ @@ -55,6 +58,7 @@ fn test_body() { assert_eq!(bytes, Bytes::from_static(STR.as_ref())); } +#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] #[test] fn test_body_gzip() { let mut srv = TestServer::new(|| { @@ -78,6 +82,7 @@ fn test_body_gzip() { assert_eq!(Bytes::from(dec), Bytes::from_static(STR.as_ref())); } +#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] #[test] fn test_body_encoding_override() { let mut srv = TestServer::new(|| { @@ -104,6 +109,7 @@ fn test_body_encoding_override() { assert_eq!(Bytes::from(dec), Bytes::from_static(STR.as_ref())); } +#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] #[test] fn test_body_gzip_large() { let data = STR.repeat(10); @@ -134,6 +140,7 @@ fn test_body_gzip_large() { assert_eq!(Bytes::from(dec), Bytes::from(data)); } +#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] #[test] fn test_body_gzip_large_random() { let data = rand::thread_rng() @@ -168,6 +175,7 @@ fn test_body_gzip_large_random() { assert_eq!(Bytes::from(dec), Bytes::from(data)); } +#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] #[test] fn test_body_chunked_implicit() { let mut srv = TestServer::new(move || { @@ -200,6 +208,7 @@ fn test_body_chunked_implicit() { } #[test] +#[cfg(feature = "brotli")] fn test_body_br_streaming() { let mut srv = TestServer::new(move || { h1::H1Service::new( @@ -277,6 +286,7 @@ fn test_no_chunking() { } #[test] +#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] fn test_body_deflate() { let mut srv = TestServer::new(move || { h1::H1Service::new( @@ -303,6 +313,7 @@ fn test_body_deflate() { } #[test] +#[cfg(any(feature = "brotli"))] fn test_body_brotli() { let mut srv = TestServer::new(move || { h1::H1Service::new( @@ -336,6 +347,7 @@ fn test_body_brotli() { } #[test] +#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] fn test_encoding() { let mut srv = TestServer::new(move || { HttpService::new( @@ -364,6 +376,7 @@ fn test_encoding() { } #[test] +#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] fn test_gzip_encoding() { let mut srv = TestServer::new(move || { HttpService::new( @@ -392,6 +405,7 @@ fn test_gzip_encoding() { } #[test] +#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] fn test_gzip_encoding_large() { let data = STR.repeat(10); let mut srv = TestServer::new(move || { @@ -421,6 +435,7 @@ fn test_gzip_encoding_large() { } #[test] +#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] fn test_reading_gzip_encoding_large_random() { let data = rand::thread_rng() .sample_iter(&Alphanumeric) @@ -455,6 +470,7 @@ fn test_reading_gzip_encoding_large_random() { } #[test] +#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] fn test_reading_deflate_encoding() { let mut srv = TestServer::new(move || { h1::H1Service::new( @@ -483,6 +499,7 @@ fn test_reading_deflate_encoding() { } #[test] +#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] fn test_reading_deflate_encoding_large() { let data = STR.repeat(10); let mut srv = TestServer::new(move || { @@ -512,6 +529,7 @@ fn test_reading_deflate_encoding_large() { } #[test] +#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] fn test_reading_deflate_encoding_large_random() { let data = rand::thread_rng() .sample_iter(&Alphanumeric) @@ -545,8 +563,8 @@ fn test_reading_deflate_encoding_large_random() { assert_eq!(bytes, Bytes::from(data)); } -#[cfg(feature = "brotli")] #[test] +#[cfg(feature = "brotli")] fn test_brotli_encoding() { let mut srv = TestServer::new(move || { h1::H1Service::new(