mirror of
https://github.com/fafhrd91/actix-net
synced 2025-01-31 12:42:09 +01:00
add NewServiceExt tests
This commit is contained in:
parent
90ad1b12a8
commit
4827990298
@ -230,7 +230,7 @@ mod tests {
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use service::{Service, ServiceExt};
|
use service::{NewServiceExt, Service, ServiceExt};
|
||||||
|
|
||||||
struct Srv1(Rc<Cell<usize>>);
|
struct Srv1(Rc<Cell<usize>>);
|
||||||
impl Service for Srv1 {
|
impl Service for Srv1 {
|
||||||
@ -286,4 +286,21 @@ mod tests {
|
|||||||
assert!(res.is_ok());
|
assert!(res.is_ok());
|
||||||
assert_eq!(res.unwrap(), Async::Ready(("srv1", "srv2")));
|
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!()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -173,7 +173,9 @@ mod tests {
|
|||||||
use futures::future::{ok, FutureResult};
|
use futures::future::{ok, FutureResult};
|
||||||
use futures::{Async, Future, Poll};
|
use futures::{Async, Future, Poll};
|
||||||
|
|
||||||
use service::{IntoService, Service, ServiceExt};
|
use service::{
|
||||||
|
IntoNewService, IntoService, NewService, NewServiceExt, Service, ServiceExt,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct Srv;
|
struct Srv;
|
||||||
@ -204,4 +206,22 @@ mod tests {
|
|||||||
assert!(res.is_ok());
|
assert!(res.is_ok());
|
||||||
assert_eq!(res.unwrap(), Async::Ready(("srv", ())));
|
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!()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -217,5 +217,4 @@ mod tests {
|
|||||||
panic!()
|
panic!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -189,7 +189,7 @@ mod tests {
|
|||||||
use futures::future::{ok, FutureResult};
|
use futures::future::{ok, FutureResult};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use service::{Service, ServiceExt};
|
use service::{IntoNewService, NewServiceExt, Service, ServiceExt};
|
||||||
|
|
||||||
struct Srv;
|
struct Srv;
|
||||||
impl Service for Srv {
|
impl Service for Srv {
|
||||||
@ -222,4 +222,17 @@ mod tests {
|
|||||||
assert!(res.is_ok());
|
assert!(res.is_ok());
|
||||||
assert_eq!(res.unwrap(), Async::Ready("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!()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -191,7 +191,7 @@ mod tests {
|
|||||||
use futures::future::{err, FutureResult};
|
use futures::future::{err, FutureResult};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use service::{Service, ServiceExt};
|
use service::{IntoNewService, NewServiceExt, Service, ServiceExt};
|
||||||
|
|
||||||
struct Srv;
|
struct Srv;
|
||||||
|
|
||||||
@ -225,4 +225,17 @@ mod tests {
|
|||||||
assert!(res.is_err());
|
assert!(res.is_err());
|
||||||
assert_eq!(res.err().unwrap(), "error");
|
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!()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user