From b79187a42599d8ccf368ae6645816da9655dddf0 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Sat, 14 Oct 2017 23:14:26 -0700 Subject: [PATCH] more tests --- .travis.yml | 2 +- src/date.rs | 9 +++++++++ src/error.rs | 16 +++++++++++++++- tests/test_httpmessage.rs | 3 +++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 59370ebe7..f632d72e8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,7 +40,7 @@ script: # Upload docs after_success: - | - if [[ "$TRAVIS_OS_NAME" == "linux" && "$TRAVIS_PULL_REQUEST" = "false" && "$TRAVIS_BRANCH" == "master" && "$TRAVIS_RUST_VERSION" == "stable" ]]; then + if [[ "$TRAVIS_OS_NAME" == "linux" && "$TRAVIS_PULL_REQUEST" = "false" && "$TRAVIS_BRANCH" == "master" && "$TRAVIS_RUST_VERSION" == "nightly" ]]; then cargo doc --no-deps && echo "" > target/doc/index.html && git clone https://github.com/davisp/ghp-import.git && diff --git a/src/date.rs b/src/date.rs index 294efa212..a5f456f96 100644 --- a/src/date.rs +++ b/src/date.rs @@ -58,3 +58,12 @@ impl fmt::Write for CachedDate { fn test_date_len() { assert_eq!(DATE_VALUE_LENGTH, "Sun, 06 Nov 1994 08:49:37 GMT".len()); } + +#[test] +fn test_date() { + let mut buf1 = BytesMut::new(); + extend(&mut buf1); + let mut buf2 = BytesMut::new(); + extend(&mut buf2); + assert_eq!(buf1, buf2); +} diff --git a/src/error.rs b/src/error.rs index e0625debb..b1ab27338 100644 --- a/src/error.rs +++ b/src/error.rs @@ -144,7 +144,21 @@ mod tests { use std::error::Error as StdError; use std::io; use httparse; - use super::ParseError; + use http::StatusCode; + use cookie::ParseError as CookieParseError; + use super::{ParseError, HttpResponse, HttpRangeParseError}; + + #[test] + fn test_into_response() { + let resp: HttpResponse = ParseError::Incomplete.into(); + assert_eq!(resp.status(), StatusCode::BAD_REQUEST); + + let resp: HttpResponse = HttpRangeParseError::InvalidRange.into(); + assert_eq!(resp.status(), StatusCode::BAD_REQUEST); + + let resp: HttpResponse = CookieParseError::EmptyName.into(); + assert_eq!(resp.status(), StatusCode::BAD_REQUEST); +} #[test] fn test_cause() { diff --git a/tests/test_httpmessage.rs b/tests/test_httpmessage.rs index 4d4530d26..98004c7de 100644 --- a/tests/test_httpmessage.rs +++ b/tests/test_httpmessage.rs @@ -39,6 +39,9 @@ fn test_request_cookies() { let cookie = cookie.unwrap(); assert_eq!(cookie.name(), "cookie1"); assert_eq!(cookie.value(), "value1"); + + let cookie = req.cookie("cookie-unknown"); + assert!(cookie.is_none()); } #[test]