From 337c2febe34e5d3781076d348c1d732e3035f49b Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Thu, 2 May 2019 09:49:10 -0700 Subject: [PATCH] add more tests --- actix-web-codegen/tests/test_macro.rs | 31 +++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/actix-web-codegen/tests/test_macro.rs b/actix-web-codegen/tests/test_macro.rs index dd105785d..9b9ec6f3b 100644 --- a/actix-web-codegen/tests/test_macro.rs +++ b/actix-web-codegen/tests/test_macro.rs @@ -1,7 +1,7 @@ use actix_http::HttpService; use actix_http_test::TestServer; use actix_web::{http, App, HttpResponse, Responder}; -use actix_web_codegen::get; +use actix_web_codegen::{get, post, put}; use futures::{future, Future}; #[get("/test")] @@ -9,6 +9,16 @@ fn test() -> impl Responder { HttpResponse::Ok() } +#[put("/test")] +fn put_test() -> impl Responder { + HttpResponse::Created() +} + +#[post("/test")] +fn post_test() -> impl Responder { + HttpResponse::NoContent() +} + #[get("/test")] fn auto_async() -> impl Future { future::ok(HttpResponse::Ok().finish()) @@ -21,11 +31,28 @@ fn auto_sync() -> impl Future { #[test] fn test_body() { - let mut srv = TestServer::new(|| HttpService::new(App::new().service(test))); + let mut srv = TestServer::new(|| { + HttpService::new( + App::new() + .service(post_test) + .service(put_test) + .service(test), + ) + }); let request = srv.request(http::Method::GET, srv.url("/test")); let response = srv.block_on(request.send()).unwrap(); assert!(response.status().is_success()); + let request = srv.request(http::Method::PUT, srv.url("/test")); + let response = srv.block_on(request.send()).unwrap(); + assert!(response.status().is_success()); + assert_eq!(response.status(), http::StatusCode::CREATED); + + let request = srv.request(http::Method::POST, srv.url("/test")); + let response = srv.block_on(request.send()).unwrap(); + assert!(response.status().is_success()); + assert_eq!(response.status(), http::StatusCode::NO_CONTENT); + let mut srv = TestServer::new(|| HttpService::new(App::new().service(auto_sync))); let request = srv.request(http::Method::GET, srv.url("/test")); let response = srv.block_on(request.send()).unwrap();