mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-24 07:53:00 +01:00
Add more tests for route
This commit is contained in:
parent
b8829bbf22
commit
9680423025
80
src/app.rs
80
src/app.rs
@ -526,84 +526,4 @@ mod tests {
|
|||||||
let resp = block_on(srv.call(req)).unwrap();
|
let resp = block_on(srv.call(req)).unwrap();
|
||||||
assert_eq!(resp.status(), StatusCode::INTERNAL_SERVER_ERROR);
|
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);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ pub mod dev {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub mod web {
|
pub mod web {
|
||||||
use actix_http::{http::Method, Error, Response};
|
use actix_http::{http::Method, Response};
|
||||||
use futures::IntoFuture;
|
use futures::IntoFuture;
|
||||||
|
|
||||||
pub use actix_http::Response as HttpResponse;
|
pub use actix_http::Response as HttpResponse;
|
||||||
@ -93,6 +93,7 @@ pub mod web {
|
|||||||
use crate::route::Route;
|
use crate::route::Route;
|
||||||
use crate::scope::Scope;
|
use crate::scope::Scope;
|
||||||
|
|
||||||
|
pub use crate::error::Error;
|
||||||
pub use crate::extract::{Form, Json, Path, Payload, Query};
|
pub use crate::extract::{Form, Json, Path, Payload, Query};
|
||||||
pub use crate::extract::{FormConfig, JsonConfig, PayloadConfig};
|
pub use crate::extract::{FormConfig, JsonConfig, PayloadConfig};
|
||||||
pub use crate::request::HttpRequest;
|
pub use crate::request::HttpRequest;
|
||||||
|
38
src/route.rs
38
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user