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

update tests

This commit is contained in:
Nikolay Kim 2019-04-14 20:20:33 -07:00
parent f9078d41cd
commit ab4fda6084
4 changed files with 59 additions and 1 deletions

View File

@ -544,6 +544,8 @@ impl fmt::Debug for ClientRequest {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::time::SystemTime;
use super::*; use super::*;
use crate::Client; use crate::Client;
@ -555,6 +557,21 @@ mod tests {
assert!(repr.contains("x-test")); assert!(repr.contains("x-test"));
} }
#[test]
fn test_basics() {
let mut req = Client::new()
.put("/")
.version(Version::HTTP_2)
.set(header::Date(SystemTime::now().into()))
.content_type("plain/text")
.content_length(100);
assert!(req.headers().contains_key(header::CONTENT_TYPE));
assert!(req.headers().contains_key(header::DATE));
assert_eq!(req.head.version, Version::HTTP_2);
let _ = req.headers_mut();
let _ = req.send_body("");
}
#[test] #[test]
fn test_client_header() { fn test_client_header() {
let req = Client::build() let req = Client::build()

View File

@ -134,3 +134,23 @@ impl TestResponse {
} }
} }
} }
#[cfg(test)]
mod tests {
use std::time::SystemTime;
use super::*;
use crate::{cookie, http::header};
#[test]
fn test_basics() {
let res = TestResponse::default()
.version(Version::HTTP_2)
.set(header::Date(SystemTime::now().into()))
.cookie(cookie::Cookie::build("name", "value").finish())
.finish();
assert!(res.headers().contains_key(header::SET_COOKIE));
assert!(res.headers().contains_key(header::DATE));
assert_eq!(res.version(), Version::HTTP_2);
}
}

View File

@ -455,10 +455,20 @@ mod tests {
.max_frame_size(100) .max_frame_size(100)
.server_mode() .server_mode()
.protocols(&["v1", "v2"]) .protocols(&["v1", "v2"])
.set_header_if_none(header::CONTENT_TYPE, "json")
.set_header_if_none(header::CONTENT_TYPE, "text")
.cookie(Cookie::build("cookie1", "value1").finish()); .cookie(Cookie::build("cookie1", "value1").finish());
assert_eq!(req.origin.unwrap().to_str().unwrap(), "test-origin"); assert_eq!(
req.origin.as_ref().unwrap().to_str().unwrap(),
"test-origin"
);
assert_eq!(req.max_size, 100); assert_eq!(req.max_size, 100);
assert_eq!(req.server_mode, true); assert_eq!(req.server_mode, true);
assert_eq!(req.protocols, Some("v1,v2".to_string())); assert_eq!(req.protocols, Some("v1,v2".to_string()));
assert_eq!(
req.head.headers.get(header::CONTENT_TYPE).unwrap(),
header::HeaderValue::from_static("json")
);
let _ = req.connect();
} }
} }

View File

@ -852,6 +852,17 @@ mod tests {
assert_eq!(resp.status(), StatusCode::OK); assert_eq!(resp.status(), StatusCode::OK);
} }
#[test]
fn default() {
let mut cors =
block_on(Cors::default().new_transform(test::ok_service())).unwrap();
let req = TestRequest::with_header("Origin", "https://www.example.com")
.to_srv_request();
let resp = test::call_success(&mut cors, req);
assert_eq!(resp.status(), StatusCode::OK);
}
#[test] #[test]
fn test_preflight() { fn test_preflight() {
let mut cors = Cors::new() let mut cors = Cors::new()