diff --git a/src/service/and_then.rs b/src/service/and_then.rs index db69df19..f2665637 100644 --- a/src/service/and_then.rs +++ b/src/service/and_then.rs @@ -230,7 +230,7 @@ mod tests { use std::rc::Rc; use super::*; - use service::{Service, ServiceExt}; + use service::{NewServiceExt, Service, ServiceExt}; struct Srv1(Rc>); impl Service for Srv1 { @@ -286,4 +286,21 @@ mod tests { assert!(res.is_ok()); assert_eq!(res.unwrap(), Async::Ready(("srv1", "srv2"))); } + + #[test] + fn test_new_service() { + let cnt = Rc::new(Cell::new(0)); + let cnt2 = cnt.clone(); + let blank = move || Ok::<_, ()>(Srv1(cnt2.clone())); + let new_srv = blank + .into_new_service() + .and_then(move || Ok(Srv2(cnt.clone()))); + if let Async::Ready(mut srv) = new_srv.new_service().poll().unwrap() { + let res = srv.call("srv1").poll(); + assert!(res.is_ok()); + assert_eq!(res.unwrap(), Async::Ready(("srv1", "srv2"))); + } else { + panic!() + } + } } diff --git a/src/service/apply.rs b/src/service/apply.rs index 06da34c7..9161775c 100644 --- a/src/service/apply.rs +++ b/src/service/apply.rs @@ -173,7 +173,9 @@ mod tests { use futures::future::{ok, FutureResult}; use futures::{Async, Future, Poll}; - use service::{IntoService, Service, ServiceExt}; + use service::{ + IntoNewService, IntoService, NewService, NewServiceExt, Service, ServiceExt, + }; #[derive(Clone)] struct Srv; @@ -204,4 +206,22 @@ mod tests { assert!(res.is_ok()); assert_eq!(res.unwrap(), Async::Ready(("srv", ()))); } + + #[test] + fn test_new_service() { + let blank = || Ok::<_, ()>((|req| Ok(req)).into_service()); + + let new_srv = blank.into_new_service().apply( + || Ok(Srv), + |req: &'static str, srv| srv.call(()).map(move |res| (req, res)), + ); + if let Async::Ready(mut srv) = new_srv.new_service().poll().unwrap() { + assert!(srv.poll_ready().is_ok()); + let res = srv.call("srv").poll(); + assert!(res.is_ok()); + assert_eq!(res.unwrap(), Async::Ready(("srv", ()))); + } else { + panic!() + } + } } diff --git a/src/service/from_err.rs b/src/service/from_err.rs index c4ee7618..3c6961a0 100644 --- a/src/service/from_err.rs +++ b/src/service/from_err.rs @@ -217,5 +217,4 @@ mod tests { panic!() } } - } diff --git a/src/service/map.rs b/src/service/map.rs index 7c119953..e44a1d2d 100644 --- a/src/service/map.rs +++ b/src/service/map.rs @@ -189,7 +189,7 @@ mod tests { use futures::future::{ok, FutureResult}; use super::*; - use service::{Service, ServiceExt}; + use service::{IntoNewService, NewServiceExt, Service, ServiceExt}; struct Srv; impl Service for Srv { @@ -222,4 +222,17 @@ mod tests { assert!(res.is_ok()); assert_eq!(res.unwrap(), Async::Ready("ok")); } + + #[test] + fn test_new_service() { + let blank = || Ok::<_, ()>(Srv); + let new_srv = blank.into_new_service().map(|_| "ok"); + if let Async::Ready(mut srv) = new_srv.new_service().poll().unwrap() { + let res = srv.call(()).poll(); + assert!(res.is_ok()); + assert_eq!(res.unwrap(), Async::Ready("ok")); + } else { + panic!() + } + } } diff --git a/src/service/map_err.rs b/src/service/map_err.rs index d69bd143..6bef7c05 100644 --- a/src/service/map_err.rs +++ b/src/service/map_err.rs @@ -191,7 +191,7 @@ mod tests { use futures::future::{err, FutureResult}; use super::*; - use service::{Service, ServiceExt}; + use service::{IntoNewService, NewServiceExt, Service, ServiceExt}; struct Srv; @@ -225,4 +225,17 @@ mod tests { assert!(res.is_err()); assert_eq!(res.err().unwrap(), "error"); } + + #[test] + fn test_new_service() { + let blank = || Ok::<_, ()>(Srv); + let new_srv = blank.into_new_service().map_err(|_| "error"); + if let Async::Ready(mut srv) = new_srv.new_service().poll().unwrap() { + let res = srv.call(()).poll(); + assert!(res.is_err()); + assert_eq!(res.err().unwrap(), "error"); + } else { + panic!() + } + } }