1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-01-18 20:01:48 +01:00

add NewServiceExt tests

This commit is contained in:
Nikolay Kim 2018-09-17 19:21:24 -07:00
parent 90ad1b12a8
commit 4827990298
5 changed files with 67 additions and 5 deletions

View File

@ -230,7 +230,7 @@ mod tests {
use std::rc::Rc;
use super::*;
use service::{Service, ServiceExt};
use service::{NewServiceExt, Service, ServiceExt};
struct Srv1(Rc<Cell<usize>>);
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!()
}
}
}

View File

@ -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!()
}
}
}

View File

@ -217,5 +217,4 @@ mod tests {
panic!()
}
}
}

View File

@ -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!()
}
}
}

View File

@ -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!()
}
}
}