diff --git a/src/app.rs b/src/app.rs index 54b5ded2..2e2a8c2d 100644 --- a/src/app.rs +++ b/src/app.rs @@ -526,84 +526,4 @@ mod tests { let resp = block_on(srv.call(req)).unwrap(); assert_eq!(resp.status(), StatusCode::INTERNAL_SERVER_ERROR); } - - // #[test] - // fn test_handler() { - // let app = App::new() - // .handler("/test", |_: &_| HttpResponse::Ok()) - // .finish(); - - // let req = TestRequest::with_uri("/test").request(); - // let resp = app.run(req); - // assert_eq!(resp.as_msg().status(), StatusCode::OK); - - // let req = TestRequest::with_uri("/test/").request(); - // let resp = app.run(req); - // assert_eq!(resp.as_msg().status(), StatusCode::OK); - - // let req = TestRequest::with_uri("/test/app").request(); - // let resp = app.run(req); - // assert_eq!(resp.as_msg().status(), StatusCode::OK); - - // let req = TestRequest::with_uri("/testapp").request(); - // let resp = app.run(req); - // assert_eq!(resp.as_msg().status(), StatusCode::NOT_FOUND); - - // let req = TestRequest::with_uri("/blah").request(); - // let resp = app.run(req); - // assert_eq!(resp.as_msg().status(), StatusCode::NOT_FOUND); - // } - - // #[test] - // fn test_handler2() { - // let app = App::new() - // .handler("test", |_: &_| HttpResponse::Ok()) - // .finish(); - - // let req = TestRequest::with_uri("/test").request(); - // let resp = app.run(req); - // assert_eq!(resp.as_msg().status(), StatusCode::OK); - - // let req = TestRequest::with_uri("/test/").request(); - // let resp = app.run(req); - // assert_eq!(resp.as_msg().status(), StatusCode::OK); - - // let req = TestRequest::with_uri("/test/app").request(); - // let resp = app.run(req); - // assert_eq!(resp.as_msg().status(), StatusCode::OK); - - // let req = TestRequest::with_uri("/testapp").request(); - // let resp = app.run(req); - // assert_eq!(resp.as_msg().status(), StatusCode::NOT_FOUND); - - // let req = TestRequest::with_uri("/blah").request(); - // let resp = app.run(req); - // assert_eq!(resp.as_msg().status(), StatusCode::NOT_FOUND); - // } - - // #[test] - // fn test_route() { - // let app = App::new() - // .route("/test", Method::GET, |_: HttpRequest| HttpResponse::Ok()) - // .route("/test", Method::POST, |_: HttpRequest| { - // HttpResponse::Created() - // }) - // .finish(); - - // let req = TestRequest::with_uri("/test").method(Method::GET).request(); - // let resp = app.run(req); - // assert_eq!(resp.as_msg().status(), StatusCode::OK); - - // let req = TestRequest::with_uri("/test") - // .method(Method::POST) - // .request(); - // let resp = app.run(req); - // assert_eq!(resp.as_msg().status(), StatusCode::CREATED); - - // let req = TestRequest::with_uri("/test") - // .method(Method::HEAD) - // .request(); - // let resp = app.run(req); - // assert_eq!(resp.as_msg().status(), StatusCode::NOT_FOUND); - // } } diff --git a/src/lib.rs b/src/lib.rs index c04480af..62f6399d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -79,7 +79,7 @@ pub mod dev { } pub mod web { - use actix_http::{http::Method, Error, Response}; + use actix_http::{http::Method, Response}; use futures::IntoFuture; pub use actix_http::Response as HttpResponse; @@ -93,6 +93,7 @@ pub mod web { use crate::route::Route; use crate::scope::Scope; + pub use crate::error::Error; pub use crate::extract::{Form, Json, Path, Payload, Query}; pub use crate::extract::{FormConfig, JsonConfig, PayloadConfig}; pub use crate::request::HttpRequest; diff --git a/src/route.rs b/src/route.rs index 707da3d8..5d339a3b 100644 --- a/src/route.rs +++ b/src/route.rs @@ -424,3 +424,41 @@ where })) } } + +#[cfg(test)] +mod tests { + use crate::http::{Method, StatusCode}; + use crate::test::{call_success, init_service, TestRequest}; + use crate::{web, App, Error, HttpResponse}; + + #[test] + fn test_route() { + let mut srv = init_service( + App::new().service( + web::resource("/test") + .route(web::get().to(|| HttpResponse::Ok())) + .route( + web::post().to_async(|| Ok::<_, Error>(HttpResponse::Created())), + ), + ), + ); + + let req = TestRequest::with_uri("/test") + .method(Method::GET) + .to_request(); + let resp = call_success(&mut srv, req); + assert_eq!(resp.status(), StatusCode::OK); + + let req = TestRequest::with_uri("/test") + .method(Method::POST) + .to_request(); + let resp = call_success(&mut srv, req); + assert_eq!(resp.status(), StatusCode::CREATED); + + let req = TestRequest::with_uri("/test") + .method(Method::HEAD) + .to_request(); + let resp = call_success(&mut srv, req); + assert_eq!(resp.status(), StatusCode::NOT_FOUND); + } +}