mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-23 16:21:06 +01:00
add tests to scope and resource for returning from fns
This commit is contained in:
parent
f8488aff1e
commit
40a0162074
@ -709,8 +709,10 @@ mod tests {
|
||||
assert_eq!(body, Bytes::from_static(b"https://youtube.com/watch/12345"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_be_returned_from_fn() {
|
||||
/// compile-only test for returning app type from function
|
||||
pub fn foreign_app_type() -> App<
|
||||
pub fn my_app() -> App<
|
||||
impl ServiceFactory<
|
||||
ServiceRequest,
|
||||
Response = ServiceResponse<impl MessageBody>,
|
||||
@ -725,8 +727,6 @@ mod tests {
|
||||
.route("/", web::to(|| async { "hello" }))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn return_foreign_app_type() {
|
||||
let _app = foreign_app_type();
|
||||
let _ = init_service(my_app());
|
||||
}
|
||||
}
|
||||
|
@ -505,18 +505,48 @@ mod tests {
|
||||
use actix_service::Service;
|
||||
use actix_utils::future::ok;
|
||||
|
||||
use super::*;
|
||||
use crate::{
|
||||
guard,
|
||||
http::{
|
||||
header::{self, HeaderValue},
|
||||
Method, StatusCode,
|
||||
},
|
||||
middleware::DefaultHeaders,
|
||||
middleware::{Compat, DefaultHeaders},
|
||||
service::{ServiceRequest, ServiceResponse},
|
||||
test::{call_service, init_service, TestRequest},
|
||||
web, App, Error, HttpMessage, HttpResponse,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn can_be_returned_from_fn() {
|
||||
fn my_resource() -> Resource {
|
||||
web::resource("/test").route(web::get().to(|| async { "hello" }))
|
||||
}
|
||||
|
||||
fn my_compat_resource() -> Resource<
|
||||
impl ServiceFactory<
|
||||
ServiceRequest,
|
||||
Config = (),
|
||||
Response = ServiceResponse,
|
||||
Error = Error,
|
||||
InitError = (),
|
||||
>,
|
||||
> {
|
||||
web::resource("/test-compat")
|
||||
// .wrap_fn(|req, srv| {
|
||||
// let fut = srv.call(req);
|
||||
// async { Ok(fut.await?.map_into_right_body::<()>()) }
|
||||
// })
|
||||
.wrap(Compat::new(DefaultHeaders::new()))
|
||||
.route(web::get().to(|| async { "hello" }))
|
||||
}
|
||||
|
||||
App::new()
|
||||
.service(my_resource())
|
||||
.service(my_compat_resource());
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_middleware() {
|
||||
let srv = init_service(
|
||||
|
31
src/scope.rs
31
src/scope.rs
@ -586,18 +586,47 @@ mod tests {
|
||||
use actix_utils::future::ok;
|
||||
use bytes::Bytes;
|
||||
|
||||
use super::*;
|
||||
use crate::{
|
||||
guard,
|
||||
http::{
|
||||
header::{self, HeaderValue},
|
||||
Method, StatusCode,
|
||||
},
|
||||
middleware::DefaultHeaders,
|
||||
middleware::{Compat, DefaultHeaders},
|
||||
service::{ServiceRequest, ServiceResponse},
|
||||
test::{assert_body_eq, call_service, init_service, read_body, TestRequest},
|
||||
web, App, HttpMessage, HttpRequest, HttpResponse,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn can_be_returned_from_fn() {
|
||||
fn my_scope() -> Scope {
|
||||
web::scope("/test")
|
||||
.service(web::resource("").route(web::get().to(|| async { "hello" })))
|
||||
}
|
||||
|
||||
fn my_compat_scope() -> Scope<
|
||||
impl ServiceFactory<
|
||||
ServiceRequest,
|
||||
Config = (),
|
||||
Response = ServiceResponse,
|
||||
Error = Error,
|
||||
InitError = (),
|
||||
>,
|
||||
> {
|
||||
web::scope("/test-compat")
|
||||
// .wrap_fn(|req, srv| {
|
||||
// let fut = srv.call(req);
|
||||
// async { Ok(fut.await?.map_into_right_body::<()>()) }
|
||||
// })
|
||||
.wrap(Compat::new(DefaultHeaders::new()))
|
||||
.service(web::resource("").route(web::get().to(|| async { "hello" })))
|
||||
}
|
||||
|
||||
App::new().service(my_scope()).service(my_compat_scope());
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_scope() {
|
||||
let srv =
|
||||
|
Loading…
Reference in New Issue
Block a user