mirror of https://github.com/fafhrd91/actix-web
Add trybuild tests for route macro
This commit is contained in:
parent
7760f46a08
commit
5801cb945d
|
@ -4,4 +4,9 @@ fn compile_macros() {
|
||||||
|
|
||||||
t.pass("tests/trybuild/simple.rs");
|
t.pass("tests/trybuild/simple.rs");
|
||||||
t.compile_fail("tests/trybuild/simple-fail.rs");
|
t.compile_fail("tests/trybuild/simple-fail.rs");
|
||||||
|
|
||||||
|
t.pass("tests/trybuild/route-ok.rs");
|
||||||
|
t.compile_fail("tests/trybuild/route-missing-method-fail.rs");
|
||||||
|
t.compile_fail("tests/trybuild/route-duplicate-method-fail.rs");
|
||||||
|
t.compile_fail("tests/trybuild/route-unexpected-method-fail.rs");
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
use actix_web::*;
|
||||||
|
|
||||||
|
#[route("/", method="GET", method="GET")]
|
||||||
|
async fn index() -> impl Responder {
|
||||||
|
HttpResponse::Ok()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_web::main]
|
||||||
|
async fn main() {
|
||||||
|
let srv = test::start(|| App::new().service(index));
|
||||||
|
|
||||||
|
let request = srv.get("/");
|
||||||
|
let response = request.send().await.unwrap();
|
||||||
|
assert!(response.status().is_success());
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
error: HTTP Method defined more than once: `GET`
|
||||||
|
--> $DIR/route-duplicate-method-fail.rs:3:35
|
||||||
|
|
|
||||||
|
3 | #[route("/", method="GET", method="GET")]
|
||||||
|
| ^^^^^
|
||||||
|
|
||||||
|
error[E0425]: cannot find value `index` in this scope
|
||||||
|
--> $DIR/route-duplicate-method-fail.rs:10:49
|
||||||
|
|
|
||||||
|
10 | let srv = test::start(|| App::new().service(index));
|
||||||
|
| ^^^^^ not found in this scope
|
|
@ -0,0 +1,15 @@
|
||||||
|
use actix_web::*;
|
||||||
|
|
||||||
|
#[route("/")]
|
||||||
|
async fn index() -> impl Responder {
|
||||||
|
HttpResponse::Ok()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_web::main]
|
||||||
|
async fn main() {
|
||||||
|
let srv = test::start(|| App::new().service(index));
|
||||||
|
|
||||||
|
let request = srv.get("/");
|
||||||
|
let response = request.send().await.unwrap();
|
||||||
|
assert!(response.status().is_success());
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
error: The #[route(..)] macro requires at least one `method` attribute
|
||||||
|
--> $DIR/route-missing-method-fail.rs:3:1
|
||||||
|
|
|
||||||
|
3 | #[route("/")]
|
||||||
|
| ^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error[E0425]: cannot find value `index` in this scope
|
||||||
|
--> $DIR/route-missing-method-fail.rs:10:49
|
||||||
|
|
|
||||||
|
10 | let srv = test::start(|| App::new().service(index));
|
||||||
|
| ^^^^^ not found in this scope
|
|
@ -0,0 +1,15 @@
|
||||||
|
use actix_web::*;
|
||||||
|
|
||||||
|
#[route("/", method="GET", method="HEAD")]
|
||||||
|
async fn index() -> impl Responder {
|
||||||
|
HttpResponse::Ok()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_web::main]
|
||||||
|
async fn main() {
|
||||||
|
let srv = test::start(|| App::new().service(index));
|
||||||
|
|
||||||
|
let request = srv.get("/");
|
||||||
|
let response = request.send().await.unwrap();
|
||||||
|
assert!(response.status().is_success());
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
use actix_web::*;
|
||||||
|
|
||||||
|
#[route("/", method="UNEXPECTED")]
|
||||||
|
async fn index() -> impl Responder {
|
||||||
|
HttpResponse::Ok()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_web::main]
|
||||||
|
async fn main() {
|
||||||
|
let srv = test::start(|| App::new().service(index));
|
||||||
|
|
||||||
|
let request = srv.get("/");
|
||||||
|
let response = request.send().await.unwrap();
|
||||||
|
assert!(response.status().is_success());
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
error: Unexpected HTTP Method: `UNEXPECTED`
|
||||||
|
--> $DIR/route-unexpected-method-fail.rs:3:21
|
||||||
|
|
|
||||||
|
3 | #[route("/", method="UNEXPECTED")]
|
||||||
|
| ^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error[E0425]: cannot find value `index` in this scope
|
||||||
|
--> $DIR/route-unexpected-method-fail.rs:10:49
|
||||||
|
|
|
||||||
|
10 | let srv = test::start(|| App::new().service(index));
|
||||||
|
| ^^^^^ not found in this scope
|
Loading…
Reference in New Issue