1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-30 18:34:36 +01:00

move tests to different mods

This commit is contained in:
Nikolay Kim 2019-03-10 11:04:50 -07:00
parent b6c1135798
commit 039efc5703
3 changed files with 65 additions and 53 deletions

View File

@ -256,26 +256,6 @@ mod tests {
hello: String, hello: String,
} }
#[test]
fn test_bytes() {
let mut req = TestRequest::with_header(header::CONTENT_LENGTH, "11")
.set_payload(Bytes::from_static(b"hello=world"))
.to_from();
let s = block_on(Bytes::from_request(&mut req)).unwrap();
assert_eq!(s, Bytes::from_static(b"hello=world"));
}
#[test]
fn test_string() {
let mut req = TestRequest::with_header(header::CONTENT_LENGTH, "11")
.set_payload(Bytes::from_static(b"hello=world"))
.to_from();
let s = block_on(String::from_request(&mut req)).unwrap();
assert_eq!(s, "hello=world");
}
#[test] #[test]
fn test_option() { fn test_option() {
let mut req = TestRequest::with_header( let mut req = TestRequest::with_header(
@ -400,36 +380,4 @@ mod tests {
assert_eq!(res[1], "32".to_owned()); assert_eq!(res[1], "32".to_owned());
} }
#[test]
fn test_extract_path_single() {
let resource = ResourceDef::new("/{value}/");
let mut req = TestRequest::with_uri("/32/").to_from();
resource.match_path(req.match_info_mut());
assert_eq!(*Path::<i8>::from_request(&mut req).unwrap(), 32);
}
#[test]
fn test_tuple_extract() {
let resource = ResourceDef::new("/{key}/{value}/");
let mut req = TestRequest::with_uri("/name/user1/?id=test").to_from();
resource.match_path(req.match_info_mut());
let res = block_on(<(Path<(String, String)>,)>::from_request(&mut req)).unwrap();
assert_eq!((res.0).0, "name");
assert_eq!((res.0).1, "user1");
let res = block_on(
<(Path<(String, String)>, Path<(String, String)>)>::from_request(&mut req),
)
.unwrap();
assert_eq!((res.0).0, "name");
assert_eq!((res.0).1, "user1");
assert_eq!((res.1).0, "name");
assert_eq!((res.1).1, "user1");
let () = <()>::from_request(&mut req).unwrap();
}
} }

View File

@ -174,3 +174,45 @@ where
Self::extract(req).map_err(ErrorNotFound) Self::extract(req).map_err(ErrorNotFound)
} }
} }
#[cfg(test)]
mod tests {
use actix_router::ResourceDef;
use super::*;
use crate::test::{block_on, TestRequest};
#[test]
fn test_extract_path_single() {
let resource = ResourceDef::new("/{value}/");
let mut req = TestRequest::with_uri("/32/").to_from();
resource.match_path(req.match_info_mut());
assert_eq!(*Path::<i8>::from_request(&mut req).unwrap(), 32);
}
#[test]
fn test_tuple_extract() {
let resource = ResourceDef::new("/{key}/{value}/");
let mut req = TestRequest::with_uri("/name/user1/?id=test").to_from();
resource.match_path(req.match_info_mut());
let res = block_on(<(Path<(String, String)>,)>::from_request(&mut req)).unwrap();
assert_eq!((res.0).0, "name");
assert_eq!((res.0).1, "user1");
let res = block_on(
<(Path<(String, String)>, Path<(String, String)>)>::from_request(&mut req),
)
.unwrap();
assert_eq!((res.0).0, "name");
assert_eq!((res.0).1, "user1");
assert_eq!((res.1).0, "name");
assert_eq!((res.1).1, "user1");
let () = <()>::from_request(&mut req).unwrap();
}
}

View File

@ -289,9 +289,11 @@ impl Default for PayloadConfig {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use bytes::Bytes;
use super::*; use super::*;
use crate::http::header; use crate::http::header;
use crate::test::TestRequest; use crate::test::{block_on, TestRequest};
#[test] #[test]
fn test_payload_config() { fn test_payload_config() {
@ -310,4 +312,24 @@ mod tests {
TestRequest::with_header(header::CONTENT_TYPE, "application/json").to_from(); TestRequest::with_header(header::CONTENT_TYPE, "application/json").to_from();
assert!(cfg.check_mimetype(&req).is_ok()); assert!(cfg.check_mimetype(&req).is_ok());
} }
#[test]
fn test_bytes() {
let mut req = TestRequest::with_header(header::CONTENT_LENGTH, "11")
.set_payload(Bytes::from_static(b"hello=world"))
.to_from();
let s = block_on(Bytes::from_request(&mut req)).unwrap();
assert_eq!(s, Bytes::from_static(b"hello=world"));
}
#[test]
fn test_string() {
let mut req = TestRequest::with_header(header::CONTENT_LENGTH, "11")
.set_payload(Bytes::from_static(b"hello=world"))
.to_from();
let s = block_on(String::from_request(&mut req)).unwrap();
assert_eq!(s, "hello=world");
}
} }