diff --git a/ntex-http/src/error.rs b/ntex-http/src/error.rs index 8b5ff2e5..5f6d4557 100644 --- a/ntex-http/src/error.rs +++ b/ntex-http/src/error.rs @@ -147,23 +147,43 @@ mod tests { use super::*; use std::error::Error as StdError; + #[test] + fn inner_http_error() { + let e = method::Method::from_bytes(b"").unwrap_err(); + let err: Error = http::Error::from(e).into(); + let ie = err.get_ref(); + assert!(ie.is::()); + } + #[test] fn inner_error_is_invalid_status_code() { - if let Err(e) = status::StatusCode::from_u16(6666) { - let err: Error = e.into(); - let ie = err.get_ref(); - assert!(!ie.is::()); - assert!(ie.is::()); - ie.downcast_ref::().unwrap(); + let e = status::StatusCode::from_u16(6666).unwrap_err(); + let err: Error = e.into(); + let ie = err.get_ref(); + assert!(!ie.is::()); + assert!(ie.is::()); + ie.downcast_ref::().unwrap(); - assert!(err.source().is_none()); - assert!(!err.is::()); - assert!(err.is::()); + assert!(err.source().is_none()); + assert!(!err.is::()); + assert!(err.is::()); - let s = format!("{:?}", err); - assert!(s.starts_with("ntex_http::Error")); - } else { - panic!("Bad status allowed!"); - } + let s = format!("{:?}", err); + assert!(s.starts_with("ntex_http::Error")); + } + + #[test] + fn inner_error_is_invalid_method() { + let e = method::Method::from_bytes(b"").unwrap_err(); + let err: Error = e.into(); + let ie = err.get_ref(); + assert!(ie.is::()); + ie.downcast_ref::().unwrap(); + + assert!(err.source().is_none()); + assert!(err.is::()); + + let s = format!("{:?}", err); + assert!(s.starts_with("ntex_http::Error")); } } diff --git a/ntex-io/src/dispatcher.rs b/ntex-io/src/dispatcher.rs index c0aeb0d1..e5650fa3 100644 --- a/ntex-io/src/dispatcher.rs +++ b/ntex-io/src/dispatcher.rs @@ -726,6 +726,7 @@ mod tests { #[ntex::test] async fn test_basic() { + let _ = env_logger::try_init(); let (client, server) = IoTest::create(); client.remote_buffer_cap(1024); client.write("GET /test HTTP/1\r\n\r\n"); diff --git a/ntex-io/src/testing.rs b/ntex-io/src/testing.rs index 604b3627..406c42c6 100644 --- a/ntex-io/src/testing.rs +++ b/ntex-io/src/testing.rs @@ -685,5 +685,11 @@ mod tests { let res = lazy(|cx| server2.poll_write_buf(cx, b"123")).await; assert!(res.is_pending()); + + let (client, _) = IoTest::create(); + let addr: net::SocketAddr = "127.0.0.1:8080".parse().unwrap(); + let client = crate::Io::new(client.set_peer_addr(addr)); + let item = client.query::(); + assert!(format!("{:?}", item).contains("QueryItem(127.0.0.1:8080)")); } } diff --git a/ntex-net/src/connect/message.rs b/ntex-net/src/connect/message.rs index 5822a006..ae7aa168 100644 --- a/ntex-net/src/connect/message.rs +++ b/ntex-net/src/connect/message.rs @@ -296,6 +296,10 @@ mod tests { let s = "test".to_string(); assert_eq!(s.host(), "test"); assert_eq!(s.port(), None); + + let s = ByteString::from("test"); + assert_eq!(s.host(), "test"); + assert_eq!(s.port(), None); } #[test] diff --git a/ntex-net/src/connect/service.rs b/ntex-net/src/connect/service.rs index 4969b9fd..05e71ad3 100644 --- a/ntex-net/src/connect/service.rs +++ b/ntex-net/src/connect/service.rs @@ -231,7 +231,10 @@ mod tests { ntex_service::fn_service(|_| async { Ok::<_, ()>(()) }) }); - let srv = Connector::default().tag("T").memory_pool(PoolId::P5); + let srv = Connector::default() + .tag("T") + .memory_pool(PoolId::P5) + .clone(); let result = srv.connect("").await; assert!(result.is_err()); let result = srv.connect("localhost:99999").await; diff --git a/ntex-service/src/and_then.rs b/ntex-service/src/and_then.rs index e2b0489f..fb86be56 100644 --- a/ntex-service/src/and_then.rs +++ b/ntex-service/src/and_then.rs @@ -141,10 +141,12 @@ mod tests { async fn test_ready() { let cnt = Rc::new(Cell::new(0)); let cnt_sht = Rc::new(Cell::new(0)); - let srv = chain(Srv1(cnt.clone(), cnt_sht.clone())) - .and_then(Srv2(cnt.clone(), cnt_sht.clone())) - .clone() - .into_pipeline(); + let srv = Box::new( + chain(Srv1(cnt.clone(), cnt_sht.clone())) + .and_then(Srv2(cnt.clone(), cnt_sht.clone())) + .clone(), + ) + .into_pipeline(); let res = srv.ready().await; assert_eq!(res, Ok(())); assert_eq!(cnt.get(), 2); @@ -168,9 +170,11 @@ mod tests { #[ntex::test] async fn test_call() { let cnt = Rc::new(Cell::new(0)); - let srv = chain(Srv1(cnt.clone(), Rc::new(Cell::new(0)))) - .and_then(Srv2(cnt, Rc::new(Cell::new(0)))) - .into_pipeline(); + let srv = Box::new( + chain(Srv1(cnt.clone(), Rc::new(Cell::new(0)))) + .and_then(Srv2(cnt, Rc::new(Cell::new(0)))), + ) + .into_pipeline(); let res = srv.call("srv1").await; assert!(res.is_ok()); assert_eq!(res.unwrap(), ("srv1", "srv2")); diff --git a/ntex-service/src/fn_service.rs b/ntex-service/src/fn_service.rs index 4e02ba50..332e77ff 100644 --- a/ntex-service/src/fn_service.rs +++ b/ntex-service/src/fn_service.rs @@ -369,20 +369,6 @@ where } } -impl IntoServiceFactory, Req, C> - for F -where - F: Fn() -> R, - R: Future>, - S: Service, - C: 'static, -{ - #[inline] - fn into_factory(self) -> FnServiceNoConfig { - FnServiceNoConfig::new(self) - } -} - #[cfg(test)] mod tests { use ntex_util::future::lazy; diff --git a/ntex-util/src/future/either.rs b/ntex-util/src/future/either.rs index 2c142dfb..8232b410 100644 --- a/ntex-util/src/future/either.rs +++ b/ntex-util/src/future/either.rs @@ -141,11 +141,13 @@ mod test { e.as_ref(); e.as_mut(); - let e = Either::<(), ()>::Right(()); + let mut e = Either::<(), ()>::Right(()); assert!(!e.is_left()); assert!(e.is_right()); assert!(e.left().is_none()); assert!(e.right().is_some()); + e.as_ref(); + e.as_mut(); assert_eq!(Either::<(), ()>::Left(()).into_inner(), ()); assert_eq!(Either::<(), ()>::Right(()).into_inner(), ()); diff --git a/ntex-util/src/future/ready.rs b/ntex-util/src/future/ready.rs index ad97e360..0026ae5d 100644 --- a/ntex-util/src/future/ready.rs +++ b/ntex-util/src/future/ready.rs @@ -39,3 +39,22 @@ impl From> for Ready { } } } + +#[cfg(test)] +mod test { + use std::future::poll_fn; + + use super::*; + + #[ntex_macros::rt_test2] + async fn ready() { + let ok = Ok::<_, ()>("ok"); + let mut f = Ready::from(ok); + let res = poll_fn(|cx| Pin::new(&mut f).poll(cx)).await; + assert_eq!(res.unwrap(), "ok"); + let err = Err::<(), _>("err"); + let mut f = Ready::from(err); + let res = poll_fn(|cx| Pin::new(&mut f).poll(cx)).await; + assert_eq!(res.unwrap_err(), "err"); + } +}