mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-24 00:21:08 +01:00
Update: Draft
This commit is contained in:
parent
52b0d5fbf9
commit
b57b9bfa7d
@ -28,5 +28,5 @@ actix-utils = "3"
|
||||
actix-web = "4"
|
||||
|
||||
futures-core = { version = "0.3.17", default-features = false, features = ["alloc"] }
|
||||
trybuild = "1"
|
||||
trybuild = "1.0"
|
||||
rustversion = "1"
|
||||
|
@ -84,7 +84,7 @@ use quote::quote;
|
||||
|
||||
mod route;
|
||||
|
||||
/// Creates resource handler, allowing multiple HTTP method guards.
|
||||
/// Creates resource handler , allowing multiple HTTP method guards.
|
||||
///
|
||||
/// # Syntax
|
||||
/// ```plain
|
||||
@ -196,6 +196,7 @@ method_macro!(Connect, connect);
|
||||
method_macro!(Options, options);
|
||||
method_macro!(Trace, trace);
|
||||
method_macro!(Patch, patch);
|
||||
method_macro!(All, all);
|
||||
|
||||
/// Marks async main function as the Actix Web system entry-point.
|
||||
///
|
||||
|
@ -62,12 +62,13 @@ macro_rules! standard_method_type {
|
||||
$(
|
||||
$variant,
|
||||
)+
|
||||
All
|
||||
}
|
||||
|
||||
impl MethodType {
|
||||
fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
$(Self::$variant => stringify!($variant),)+
|
||||
$(Self::$variant => stringify!($variant), &MethodType::All => stringify!("All"),)+
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#[rustversion::stable(1.72)] // MSRV
|
||||
//#[rustversion::stable(1.72)] // MSRV
|
||||
#[test]
|
||||
fn compile_macros() {
|
||||
let t = trybuild::TestCases::new();
|
||||
@ -21,4 +21,5 @@ fn compile_macros() {
|
||||
t.pass("tests/trybuild/docstring-ok.rs");
|
||||
|
||||
t.pass("tests/trybuild/test-runtime.rs");
|
||||
}
|
||||
t.pass("tests/trybuild/route-any-method.rs");
|
||||
}
|
25
actix-web-codegen/tests/trybuild/route-any-method.rs
Normal file
25
actix-web-codegen/tests/trybuild/route-any-method.rs
Normal file
@ -0,0 +1,25 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use actix_web::http::Method;
|
||||
use actix_web_codegen::route;
|
||||
|
||||
#[route("/single", method = "ALL")]
|
||||
async fn index() -> String {
|
||||
"Hello Single!".to_owned()
|
||||
}
|
||||
|
||||
#[route("/multi", method = "GET", method = "ALL")]
|
||||
async fn custom() -> String {
|
||||
"Hello Multi!".to_owned()
|
||||
}
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() {
|
||||
use actix_web::App;
|
||||
|
||||
let srv = actix_test::start(|| App::new().service(index).service(custom));
|
||||
|
||||
let request = srv.request(Method::from_str("ALL").unwrap(), srv.url("/single"));
|
||||
let response = request.send().await.unwrap();
|
||||
assert!(response.status().is_success());
|
||||
}
|
@ -8,7 +8,7 @@ async fn index() -> String {
|
||||
"Hello Single!".to_owned()
|
||||
}
|
||||
|
||||
#[route("/multi", method = "GET", method = "CUSTOM")]
|
||||
#[route("/multi", method = "CUSTOM")]
|
||||
async fn custom() -> String {
|
||||
"Hello Multi!".to_owned()
|
||||
}
|
||||
@ -19,17 +19,17 @@ async fn main() {
|
||||
|
||||
let srv = actix_test::start(|| App::new().service(index).service(custom));
|
||||
|
||||
let request = srv.request(Method::GET, srv.url("/"));
|
||||
let response = request.send().await.unwrap();
|
||||
assert!(response.status().is_client_error());
|
||||
// let request = srv.request(Method::GET, srv.url("/"));
|
||||
// let response = request.send().await.unwrap();
|
||||
// assert!(response.status().is_client_error());
|
||||
|
||||
let request = srv.request(Method::from_str("CUSTOM").unwrap(), srv.url("/single"));
|
||||
let response = request.send().await.unwrap();
|
||||
assert!(response.status().is_success());
|
||||
|
||||
let request = srv.request(Method::GET, srv.url("/multi"));
|
||||
let response = request.send().await.unwrap();
|
||||
assert!(response.status().is_success());
|
||||
// let request = srv.request(Method::GET, srv.url("/multi"));
|
||||
// let response = request.send().await.unwrap();
|
||||
// assert!(response.status().is_success());
|
||||
|
||||
let request = srv.request(Method::from_str("CUSTOM").unwrap(), srv.url("/multi"));
|
||||
let response = request.send().await.unwrap();
|
||||
|
Loading…
Reference in New Issue
Block a user