From efada51f12232b53a7f30281d860994847644643 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Mon, 23 Oct 2017 14:26:01 -0700 Subject: [PATCH] add exclude pattern for tests --- .travis.yml | 4 ++-- src/httprequest.rs | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index eff26523..33549eef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -61,8 +61,8 @@ after_success: make install DESTDIR=../../kcov-build && cd ../.. && rm -rf kcov-master && - for file in target/debug/actix_web-*[^\.d]; do mkdir -p "target/cov/$(basename $file)"; ./kcov-build/usr/local/bin/kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/$(basename $file)" "$file"; done && - for file in target/debug/test_*[^\.d]; do mkdir -p "target/cov/$(basename $file)"; ./kcov-build/usr/local/bin/kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/$(basename $file)" "$file"; done && + for file in target/debug/actix_web-*[^\.d]; do mkdir -p "target/cov/$(basename $file)"; ./kcov-build/usr/local/bin/kcov --exclude-pattern=/.cargo,/usr/lib --exclude-region='#[cfg(test)]:' --verify "target/cov/$(basename $file)" "$file"; done && + for file in target/debug/test_*[^\.d]; do mkdir -p "target/cov/$(basename $file)"; ./kcov-build/usr/local/bin/kcov --exclude-pattern=/.cargo,/usr/lib,test_ --verify "target/cov/$(basename $file)" "$file"; done && bash <(curl -s https://codecov.io/bash) && echo "Uploaded code coverage" fi diff --git a/src/httprequest.rs b/src/httprequest.rs index d101d40e..84d02214 100644 --- a/src/httprequest.rs +++ b/src/httprequest.rs @@ -288,3 +288,58 @@ impl Future for UrlEncoded { } } } + +#[cfg(test)] +mod tests { + use super::*; + use http::{Uri, HttpTryFrom}; + // use futures::future::{lazy, result}; + // use tokio_core::reactor::Core; + use payload::Payload; + + #[test] + fn test_urlencoded_error() { + let mut headers = HeaderMap::new(); + headers.insert(header::TRANSFER_ENCODING, + header::HeaderValue::from_static("chunked")); + let req = HttpRequest::new( + Method::GET, Uri::try_from("/").unwrap(), Version::HTTP_11, headers); + + let (_, payload) = Payload::new(false); + assert!(req.urlencoded(payload).is_err()); + + let mut headers = HeaderMap::new(); + headers.insert(header::CONTENT_TYPE, + header::HeaderValue::from_static("application/x-www-form-urlencoded")); + headers.insert(header::CONTENT_LENGTH, + header::HeaderValue::from_static("xxxx")); + let req = HttpRequest::new( + Method::GET, Uri::try_from("/").unwrap(), Version::HTTP_11, headers); + + let (_, payload) = Payload::new(false); + assert!(req.urlencoded(payload).is_err()); + + let mut headers = HeaderMap::new(); + headers.insert(header::CONTENT_TYPE, + header::HeaderValue::from_static("application/x-www-form-urlencoded")); + headers.insert(header::CONTENT_LENGTH, + header::HeaderValue::from_static("1000000")); + let req = HttpRequest::new( + Method::GET, Uri::try_from("/").unwrap(), Version::HTTP_11, headers); + + let (_, payload) = Payload::new(false); + assert!(req.urlencoded(payload).is_err()); + + let mut headers = HeaderMap::new(); + headers.insert(header::CONTENT_TYPE, + header::HeaderValue::from_static("text/plain")); + headers.insert(header::CONTENT_LENGTH, + header::HeaderValue::from_static("10")); + let req = HttpRequest::new( + Method::GET, Uri::try_from("/").unwrap(), Version::HTTP_11, headers); + + let (_, payload) = Payload::new(false); + assert!(req.urlencoded(payload).is_err()); + } + +}