1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-24 07:53:00 +01:00

fix tests for no-default-features

This commit is contained in:
Nikolay Kim 2019-03-28 14:27:07 -07:00
parent a2c9ff3a33
commit 878f32c495
4 changed files with 47 additions and 22 deletions

View File

@ -34,7 +34,8 @@ before_script:
- export PATH=$PATH:~/.cargo/bin - export PATH=$PATH:~/.cargo/bin
script: script:
- cargo clean - cargo update
- cargo check --all --no-default-features
- cargo test --all-features --all -- --nocapture - cargo test --all-features --all -- --nocapture
# Upload docs # Upload docs

View File

@ -10,6 +10,7 @@ use actix_service::boxed::{self, BoxedNewService};
use actix_service::{ use actix_service::{
ApplyTransform, IntoNewService, IntoTransform, NewService, Transform, ApplyTransform, IntoNewService, IntoTransform, NewService, Transform,
}; };
#[cfg(any(feature = "brotli", feature = "flate2-zlib", feature = "flate2-rust"))]
use bytes::Bytes; use bytes::Bytes;
use futures::{IntoFuture, Stream}; use futures::{IntoFuture, Stream};

View File

@ -2,9 +2,8 @@ use net2::TcpBuilder;
use std::sync::mpsc; use std::sync::mpsc;
use std::{net, thread, time::Duration}; use std::{net, thread, time::Duration};
use actix_http::{client, Response}; use actix_http::Response;
use actix_web::{web, App, HttpServer};
use actix_web::{test, web, App, HttpServer};
fn unused_addr() -> net::SocketAddr { fn unused_addr() -> net::SocketAddr {
let addr: net::SocketAddr = "127.0.0.1:0".parse().unwrap(); 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 (srv, sys) = rx.recv().unwrap();
let client = test::run_on(|| { #[cfg(feature = "client")]
Ok::<_, ()>( {
awc::Client::build() use actix_http::client;
.connector( use actix_web::test;
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(); let client = test::run_on(|| {
assert!(response.status().is_success()); 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 // stop
let _ = srv.stop(false); let _ = srv.stop(false);

View File

@ -11,10 +11,13 @@ use bytes::Bytes;
use flate2::read::GzDecoder; use flate2::read::GzDecoder;
use flate2::write::{GzEncoder, ZlibDecoder, ZlibEncoder}; use flate2::write::{GzEncoder, ZlibDecoder, ZlibEncoder};
use flate2::Compression; use flate2::Compression;
use futures::stream::once; //Future, Stream use futures::stream::once;
use rand::{distributions::Alphanumeric, Rng}; 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 \ const STR: &str = "Hello World Hello World Hello World Hello World Hello World \
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())); assert_eq!(bytes, Bytes::from_static(STR.as_ref()));
} }
#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))]
#[test] #[test]
fn test_body_gzip() { fn test_body_gzip() {
let mut srv = TestServer::new(|| { let mut srv = TestServer::new(|| {
@ -78,6 +82,7 @@ fn test_body_gzip() {
assert_eq!(Bytes::from(dec), Bytes::from_static(STR.as_ref())); assert_eq!(Bytes::from(dec), Bytes::from_static(STR.as_ref()));
} }
#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))]
#[test] #[test]
fn test_body_encoding_override() { fn test_body_encoding_override() {
let mut srv = TestServer::new(|| { 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())); assert_eq!(Bytes::from(dec), Bytes::from_static(STR.as_ref()));
} }
#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))]
#[test] #[test]
fn test_body_gzip_large() { fn test_body_gzip_large() {
let data = STR.repeat(10); let data = STR.repeat(10);
@ -134,6 +140,7 @@ fn test_body_gzip_large() {
assert_eq!(Bytes::from(dec), Bytes::from(data)); assert_eq!(Bytes::from(dec), Bytes::from(data));
} }
#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))]
#[test] #[test]
fn test_body_gzip_large_random() { fn test_body_gzip_large_random() {
let data = rand::thread_rng() let data = rand::thread_rng()
@ -168,6 +175,7 @@ fn test_body_gzip_large_random() {
assert_eq!(Bytes::from(dec), Bytes::from(data)); assert_eq!(Bytes::from(dec), Bytes::from(data));
} }
#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))]
#[test] #[test]
fn test_body_chunked_implicit() { fn test_body_chunked_implicit() {
let mut srv = TestServer::new(move || { let mut srv = TestServer::new(move || {
@ -200,6 +208,7 @@ fn test_body_chunked_implicit() {
} }
#[test] #[test]
#[cfg(feature = "brotli")]
fn test_body_br_streaming() { fn test_body_br_streaming() {
let mut srv = TestServer::new(move || { let mut srv = TestServer::new(move || {
h1::H1Service::new( h1::H1Service::new(
@ -277,6 +286,7 @@ fn test_no_chunking() {
} }
#[test] #[test]
#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))]
fn test_body_deflate() { fn test_body_deflate() {
let mut srv = TestServer::new(move || { let mut srv = TestServer::new(move || {
h1::H1Service::new( h1::H1Service::new(
@ -303,6 +313,7 @@ fn test_body_deflate() {
} }
#[test] #[test]
#[cfg(any(feature = "brotli"))]
fn test_body_brotli() { fn test_body_brotli() {
let mut srv = TestServer::new(move || { let mut srv = TestServer::new(move || {
h1::H1Service::new( h1::H1Service::new(
@ -336,6 +347,7 @@ fn test_body_brotli() {
} }
#[test] #[test]
#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))]
fn test_encoding() { fn test_encoding() {
let mut srv = TestServer::new(move || { let mut srv = TestServer::new(move || {
HttpService::new( HttpService::new(
@ -364,6 +376,7 @@ fn test_encoding() {
} }
#[test] #[test]
#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))]
fn test_gzip_encoding() { fn test_gzip_encoding() {
let mut srv = TestServer::new(move || { let mut srv = TestServer::new(move || {
HttpService::new( HttpService::new(
@ -392,6 +405,7 @@ fn test_gzip_encoding() {
} }
#[test] #[test]
#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))]
fn test_gzip_encoding_large() { fn test_gzip_encoding_large() {
let data = STR.repeat(10); let data = STR.repeat(10);
let mut srv = TestServer::new(move || { let mut srv = TestServer::new(move || {
@ -421,6 +435,7 @@ fn test_gzip_encoding_large() {
} }
#[test] #[test]
#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))]
fn test_reading_gzip_encoding_large_random() { fn test_reading_gzip_encoding_large_random() {
let data = rand::thread_rng() let data = rand::thread_rng()
.sample_iter(&Alphanumeric) .sample_iter(&Alphanumeric)
@ -455,6 +470,7 @@ fn test_reading_gzip_encoding_large_random() {
} }
#[test] #[test]
#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))]
fn test_reading_deflate_encoding() { fn test_reading_deflate_encoding() {
let mut srv = TestServer::new(move || { let mut srv = TestServer::new(move || {
h1::H1Service::new( h1::H1Service::new(
@ -483,6 +499,7 @@ fn test_reading_deflate_encoding() {
} }
#[test] #[test]
#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))]
fn test_reading_deflate_encoding_large() { fn test_reading_deflate_encoding_large() {
let data = STR.repeat(10); let data = STR.repeat(10);
let mut srv = TestServer::new(move || { let mut srv = TestServer::new(move || {
@ -512,6 +529,7 @@ fn test_reading_deflate_encoding_large() {
} }
#[test] #[test]
#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))]
fn test_reading_deflate_encoding_large_random() { fn test_reading_deflate_encoding_large_random() {
let data = rand::thread_rng() let data = rand::thread_rng()
.sample_iter(&Alphanumeric) .sample_iter(&Alphanumeric)
@ -545,8 +563,8 @@ fn test_reading_deflate_encoding_large_random() {
assert_eq!(bytes, Bytes::from(data)); assert_eq!(bytes, Bytes::from(data));
} }
#[cfg(feature = "brotli")]
#[test] #[test]
#[cfg(feature = "brotli")]
fn test_brotli_encoding() { fn test_brotli_encoding() {
let mut srv = TestServer::new(move || { let mut srv = TestServer::new(move || {
h1::H1Service::new( h1::H1Service::new(