mirror of
https://github.com/ntex-rs/ntex.git
synced 2025-04-04 13:27:39 +03:00
tests cleanup
This commit is contained in:
parent
2d17a50d25
commit
34d115abba
3 changed files with 14 additions and 13 deletions
|
@ -715,9 +715,12 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_static_tail() {
|
fn test_static_tail() {
|
||||||
let re = ResourceDef::new("/*");
|
let re = ResourceDef::new("/*".to_string());
|
||||||
let tree = Tree::new(&re, 1);
|
let tree = Tree::new(&re, 1);
|
||||||
assert_eq!(tree.find(&mut Path::new("/")), None);
|
assert_eq!(
|
||||||
|
tree.find(&mut Path::new(bytestring::ByteString::from_static("/"))),
|
||||||
|
None
|
||||||
|
);
|
||||||
assert_eq!(tree.find(&mut Path::new("/profile")), Some(1));
|
assert_eq!(tree.find(&mut Path::new("/profile")), Some(1));
|
||||||
assert_eq!(tree.find(&mut Path::new("/user/profile")), Some(1));
|
assert_eq!(tree.find(&mut Path::new("/user/profile")), Some(1));
|
||||||
assert_eq!(tree.find(&mut Path::new("/user/2345")), Some(1));
|
assert_eq!(tree.find(&mut Path::new("/user/2345")), Some(1));
|
||||||
|
@ -726,7 +729,7 @@ mod tests {
|
||||||
assert_eq!(tree.find(&mut Path::new("/2345/sdg")), Some(1));
|
assert_eq!(tree.find(&mut Path::new("/2345/sdg")), Some(1));
|
||||||
assert_eq!(tree.find(&mut Path::new("/user/2345/sdg")), Some(1));
|
assert_eq!(tree.find(&mut Path::new("/user/2345/sdg")), Some(1));
|
||||||
|
|
||||||
let re = ResourceDef::new("/user*");
|
let re = ResourceDef::new(&("/user*".to_string()));
|
||||||
let tree = Tree::new(&re, 1);
|
let tree = Tree::new(&re, 1);
|
||||||
assert_eq!(tree.find(&mut Path::new("/user/profile")), Some(1));
|
assert_eq!(tree.find(&mut Path::new("/user/profile")), Some(1));
|
||||||
assert_eq!(tree.find(&mut Path::new("/user/2345")), Some(1));
|
assert_eq!(tree.find(&mut Path::new("/user/2345")), Some(1));
|
||||||
|
|
|
@ -35,28 +35,24 @@ use crate::web::{BodyEncoding, ErrorRenderer};
|
||||||
/// );
|
/// );
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub struct Compress<Err> {
|
pub struct Compress {
|
||||||
enc: ContentEncoding,
|
enc: ContentEncoding,
|
||||||
_t: PhantomData<Err>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Err> Compress<Err> {
|
impl Compress {
|
||||||
/// Create new `Compress` middleware with default encoding.
|
/// Create new `Compress` middleware with default encoding.
|
||||||
pub fn new(encoding: ContentEncoding) -> Self {
|
pub fn new(encoding: ContentEncoding) -> Self {
|
||||||
Compress {
|
Compress { enc: encoding }
|
||||||
enc: encoding,
|
|
||||||
_t: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Err> Default for Compress<Err> {
|
impl Default for Compress {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Compress::new(ContentEncoding::Auto)
|
Compress::new(ContentEncoding::Auto)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, E> Transform<S> for Compress<E>
|
impl<S, E> Transform<S> for Compress
|
||||||
where
|
where
|
||||||
S: Service<Request = WebRequest<E>, Response = WebResponse>,
|
S: Service<Request = WebRequest<E>, Response = WebResponse>,
|
||||||
E: ErrorRenderer,
|
E: ErrorRenderer,
|
||||||
|
|
|
@ -492,7 +492,7 @@ mod tests {
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
let _logger = Logger::default();
|
let _logger = Logger::default();
|
||||||
let logger = Logger::new("%% %{User-Agent}i %{X-Test}o %{HOME}e %D test")
|
let logger = Logger::new("%% %{User-Agent}i %{X-Test}o %{HOME}e %D %% test")
|
||||||
.exclude("/test");
|
.exclude("/test");
|
||||||
|
|
||||||
let srv = Transform::new_transform(&logger, srv.into_service())
|
let srv = Transform::new_transform(&logger, srv.into_service())
|
||||||
|
@ -510,6 +510,8 @@ mod tests {
|
||||||
let res = srv.call(req).await.unwrap();
|
let res = srv.call(req).await.unwrap();
|
||||||
let body = test::read_body(res).await;
|
let body = test::read_body(res).await;
|
||||||
assert_eq!(body, Bytes::from_static(b"TEST"));
|
assert_eq!(body, Bytes::from_static(b"TEST"));
|
||||||
|
assert_eq!(body.size(), BodySize::Sized(4));
|
||||||
|
drop(body);
|
||||||
|
|
||||||
let req = TestRequest::with_uri("/test").to_srv_request();
|
let req = TestRequest::with_uri("/test").to_srv_request();
|
||||||
let res = srv.call(req).await.unwrap();
|
let res = srv.call(req).await.unwrap();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue