update tests

This commit is contained in:
Nikolay Kim 2021-04-03 17:37:00 +06:00
parent 284cc4caf0
commit 9638f2bf58
10 changed files with 30 additions and 30 deletions

View file

@ -288,7 +288,7 @@ mod tests {
} }
fn call(&self, req: &'static str) -> Self::Future { fn call(&self, req: &'static str) -> Self::Future {
Ready::ok(req) Ready::Ok(req)
} }
} }
@ -307,7 +307,7 @@ mod tests {
} }
fn call(&self, req: &'static str) -> Self::Future { fn call(&self, req: &'static str) -> Self::Future {
Ready::ok((req, "srv2")) Ready::Ok((req, "srv2"))
} }
} }
@ -339,9 +339,9 @@ mod tests {
let cnt = Rc::new(Cell::new(0)); let cnt = Rc::new(Cell::new(0));
let cnt2 = cnt.clone(); let cnt2 = cnt.clone();
let new_srv = pipeline_factory(fn_factory(move || { let new_srv = pipeline_factory(fn_factory(move || {
Ready::result(Ok::<_, ()>(Srv1(cnt2.clone()))) Ready::from(Ok::<_, ()>(Srv1(cnt2.clone())))
})) }))
.and_then(move || Ready::result(Ok(Srv2(cnt.clone())))) .and_then(move || Ready::from(Ok(Srv2(cnt.clone()))))
.clone(); .clone();
let srv = new_srv.new_service(()).await.unwrap(); let srv = new_srv.new_service(()).await.unwrap();

View file

@ -308,13 +308,13 @@ mod tests {
} }
fn call(&self, _: Self::Request) -> Self::Future { fn call(&self, _: Self::Request) -> Self::Future {
Ready::ok(()) Ready::Ok(())
} }
} }
#[ntex::test] #[ntex::test]
async fn test_service() { async fn test_service() {
let srv = pipeline(Ready::<_, ()>::ok) let srv = pipeline(Ready::<_, ()>::Ok)
.and_then_apply_fn(Srv, |req: &'static str, s| { .and_then_apply_fn(Srv, |req: &'static str, s| {
let f = s.call(()); let f = s.call(());
async move { f.await.map(move |res| (req, res)) } async move { f.await.map(move |res| (req, res)) }
@ -334,9 +334,9 @@ mod tests {
#[ntex::test] #[ntex::test]
async fn test_service_factory() { async fn test_service_factory() {
let new_srv = let new_srv =
pipeline_factory(|| Ready::<_, ()>::ok(fn_service(Ready::<_, ()>::ok))) pipeline_factory(|| Ready::<_, ()>::Ok(fn_service(Ready::<_, ()>::Ok)))
.and_then_apply_fn( .and_then_apply_fn(
|| Ready::ok(Srv), || Ready::Ok(Srv),
|req: &'static str, s| { |req: &'static str, s| {
let f = s.call(()); let f = s.call(());
async move { f.await.map(move |res| (req, res)) } async move { f.await.map(move |res| (req, res)) }

View file

@ -232,7 +232,7 @@ mod tests {
} }
fn call(&self, _: ()) -> Self::Future { fn call(&self, _: ()) -> Self::Future {
Ready::ok(()) Ready::Ok(())
} }
} }
@ -264,7 +264,7 @@ mod tests {
async fn test_new_service() { async fn test_new_service() {
let new_srv = pipeline_factory( let new_srv = pipeline_factory(
apply_fn_factory( apply_fn_factory(
|| Ready::<_, ()>::ok(Srv), || Ready::<_, ()>::Ok(Srv),
|req: &'static str, srv| { |req: &'static str, srv| {
let fut = srv.call(()); let fut = srv.call(());
async move { async move {

View file

@ -238,7 +238,7 @@ mod tests {
let item2 = item.clone(); let item2 = item.clone();
let srv = apply_cfg( let srv = apply_cfg(
fn_service(move |item: usize| Ready::<_, ()>::ok(item + 1)), fn_service(move |item: usize| Ready::<_, ()>::Ok(item + 1)),
move |_: (), srv| { move |_: (), srv| {
let id = item2.get(); let id = item2.get();
let fut = srv.call(id); let fut = srv.call(id);
@ -246,7 +246,7 @@ mod tests {
async move { async move {
item.set(fut.await.unwrap()); item.set(fut.await.unwrap());
Ok::<_, ()>(fn_service(|id: usize| Ready::<_, ()>::ok(id * 2))) Ok::<_, ()>(fn_service(|id: usize| Ready::<_, ()>::Ok(id * 2)))
} }
}, },
) )
@ -265,7 +265,7 @@ mod tests {
let item2 = item.clone(); let item2 = item.clone();
let srv = apply_cfg_factory( let srv = apply_cfg_factory(
fn_service(move |item: usize| Ready::<_, ()>::ok(item + 1)), fn_service(move |item: usize| Ready::<_, ()>::Ok(item + 1)),
move |_: (), srv| { move |_: (), srv| {
let id = item2.get(); let id = item2.get();
let fut = srv.call(id); let fut = srv.call(id);
@ -273,7 +273,7 @@ mod tests {
async move { async move {
item.set(fut.await.unwrap()); item.set(fut.await.unwrap());
Ok::<_, ()>(fn_service(|id: usize| Ready::<_, ()>::ok(id * 2))) Ok::<_, ()>(fn_service(|id: usize| Ready::<_, ()>::Ok(id * 2)))
} }
}, },
) )

View file

@ -86,7 +86,7 @@ mod tests {
} }
fn call(&self, i: usize) -> Self::Future { fn call(&self, i: usize) -> Self::Future {
Ready::ok(i * 2) Ready::Ok(i * 2)
} }
} }

View file

@ -223,7 +223,7 @@ mod tests {
} }
fn call(&self, _: ()) -> Self::Future { fn call(&self, _: ()) -> Self::Future {
Ready::ok(()) Ready::Ok(())
} }
} }

View file

@ -314,7 +314,7 @@ mod tests {
let item = Rc::new(Cell::new(1usize)); let item = Rc::new(Cell::new(1usize));
let factory = map_config( let factory = map_config(
fn_service(|item: usize| Ready::<_, ()>::ok(item)), fn_service(|item: usize| Ready::<_, ()>::Ok(item)),
|t: usize| { |t: usize| {
item.set(item.get() + t); item.set(item.get() + t);
}, },
@ -327,7 +327,7 @@ mod tests {
#[ntex::test] #[ntex::test]
async fn test_unit_config() { async fn test_unit_config() {
let _ = unit_config(fn_service(|item: usize| Ready::<_, ()>::ok(item))) let _ = unit_config(fn_service(|item: usize| Ready::<_, ()>::Ok(item)))
.clone() .clone()
.new_service(10) .new_service(10)
.await; .await;
@ -343,10 +343,10 @@ mod tests {
let item = item2.clone(); let item = item2.clone();
async move { async move {
item.set(next); item.set(next);
Ok::<_, ()>(fn_service(|id: usize| Ready::<_, ()>::ok(id * 2))) Ok::<_, ()>(fn_service(|id: usize| Ready::<_, ()>::Ok(id * 2)))
} }
}), }),
fn_service(move |item: usize| Ready::<_, ()>::ok(item + 1)), fn_service(move |item: usize| Ready::<_, ()>::Ok(item + 1)),
) )
.clone() .clone()
.new_service(10) .new_service(10)

View file

@ -225,7 +225,7 @@ mod tests {
} }
fn call(&self, _: ()) -> Self::Future { fn call(&self, _: ()) -> Self::Future {
Ready::err(()) Ready::Err(())
} }
} }
@ -257,7 +257,7 @@ mod tests {
#[ntex::test] #[ntex::test]
async fn test_factory() { async fn test_factory() {
let new_srv = (|| Ready::<_, ()>::ok(Srv)) let new_srv = (|| Ready::<_, ()>::Ok(Srv))
.into_factory() .into_factory()
.map_err(|_| "error") .map_err(|_| "error")
.clone(); .clone();

View file

@ -278,8 +278,8 @@ mod tests {
fn call(&self, req: Result<&'static str, &'static str>) -> Self::Future { fn call(&self, req: Result<&'static str, &'static str>) -> Self::Future {
match req { match req {
Ok(msg) => Ready::ok(msg), Ok(msg) => Ready::Ok(msg),
Err(_) => Ready::err(()), Err(_) => Ready::Err(()),
} }
} }
} }
@ -299,8 +299,8 @@ mod tests {
fn call(&self, req: Result<&'static str, ()>) -> Self::Future { fn call(&self, req: Result<&'static str, ()>) -> Self::Future {
match req { match req {
Ok(msg) => Ready::ok((msg, "ok")), Ok(msg) => Ready::Ok((msg, "ok")),
Err(()) => Ready::ok(("srv2", "err")), Err(()) => Ready::Ok(("srv2", "err")),
} }
} }
} }
@ -334,9 +334,9 @@ mod tests {
async fn test_factory() { async fn test_factory() {
let cnt = Rc::new(Cell::new(0)); let cnt = Rc::new(Cell::new(0));
let cnt2 = cnt.clone(); let cnt2 = cnt.clone();
let blank = move || Ready::<_, ()>::ok(Srv1(cnt2.clone())); let blank = move || Ready::<_, ()>::Ok(Srv1(cnt2.clone()));
let factory = pipeline_factory(blank) let factory = pipeline_factory(blank)
.then(move || Ready::ok(Srv2(cnt.clone()))) .then(move || Ready::Ok(Srv2(cnt.clone())))
.clone(); .clone();
let srv = factory.new_service(&()).await.unwrap(); let srv = factory.new_service(&()).await.unwrap();
let res = srv.call(Ok("srv1")).await; let res = srv.call(Ok("srv1")).await;

View file

@ -249,7 +249,7 @@ mod tests {
type Future = Ready<Self::Transform, Self::InitError>; type Future = Ready<Self::Transform, Self::InitError>;
fn new_transform(&self, service: S) -> Self::Future { fn new_transform(&self, service: S) -> Self::Future {
Ready::ok(Srv(service)) Ready::Ok(Srv(service))
} }
} }
@ -275,7 +275,7 @@ mod tests {
async fn transform() { async fn transform() {
let factory = apply( let factory = apply(
Rc::new(Tr.map_init_err(|_| ()).clone()), Rc::new(Tr.map_init_err(|_| ()).clone()),
fn_service(|i: usize| Ready::<_, ()>::ok(i * 2)), fn_service(|i: usize| Ready::<_, ()>::Ok(i * 2)),
) )
.clone(); .clone();