2023-02-06 13:40:41 +01:00
|
|
|
use std::str::FromStr;
|
2020-09-16 23:37:41 +02:00
|
|
|
|
2023-02-06 18:06:47 +01:00
|
|
|
use actix_web::http::Method;
|
|
|
|
use actix_web_codegen::route;
|
|
|
|
|
|
|
|
#[route("/single", method = "CUSTOM")]
|
2020-09-25 00:54:01 +02:00
|
|
|
async fn index() -> String {
|
2023-02-06 18:06:47 +01:00
|
|
|
"Hello Single!".to_owned()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[route("/multi", method = "GET", method = "CUSTOM")]
|
|
|
|
async fn custom() -> String {
|
|
|
|
"Hello Multi!".to_owned()
|
2020-09-16 23:37:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_web::main]
|
|
|
|
async fn main() {
|
2021-04-02 09:26:59 +02:00
|
|
|
use actix_web::App;
|
2020-09-25 00:54:01 +02:00
|
|
|
|
2023-02-06 18:06:47 +01:00
|
|
|
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::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());
|
2020-09-16 23:37:41 +02:00
|
|
|
|
2023-02-06 18:06:47 +01:00
|
|
|
let request = srv.request(Method::from_str("CUSTOM").unwrap(), srv.url("/multi"));
|
2020-09-16 23:37:41 +02:00
|
|
|
let response = request.send().await.unwrap();
|
|
|
|
assert!(response.status().is_success());
|
|
|
|
}
|