From 47c52f95c62e805b5621249ab4fc3b65c3b1e565 Mon Sep 17 00:00:00 2001 From: Tess Eisenberger Date: Tue, 12 Oct 2021 18:02:05 -0700 Subject: [PATCH 1/4] Add testing helper for DELETE requests This introduces test_util.object_delete(), to go along with the existing test_util helpers. --- dropshot/src/test_util.rs | 19 +++++++++++++++++++ dropshot/tests/test_demo.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/dropshot/src/test_util.rs b/dropshot/src/test_util.rs index 3c41b3830..5b45620c0 100644 --- a/dropshot/src/test_util.rs +++ b/dropshot/src/test_util.rs @@ -613,6 +613,25 @@ pub async fn objects_post( read_json::(&mut response).await } +/** + * Issues an HTTP DELETE to the specified object URL to delete an object. + */ +pub async fn object_delete( + client: &ClientTestContext, + object_url: &str, +) -> T { + let mut response = client + .make_request_with_body( + Method::DELETE, + &object_url, + "".into(), + StatusCode::OK, + ) + .await + .unwrap(); + read_json::(&mut response).await +} + /** * Iterate a paginated collection. */ diff --git a/dropshot/tests/test_demo.rs b/dropshot/tests/test_demo.rs index d32d85d1a..a433987ac 100644 --- a/dropshot/tests/test_demo.rs +++ b/dropshot/tests/test_demo.rs @@ -18,8 +18,10 @@ use dropshot::endpoint; use dropshot::test_util::read_json; use dropshot::test_util::read_string; +use dropshot::test_util::object_delete; use dropshot::ApiDescription; use dropshot::HttpError; +use dropshot::HttpResponseDeleted; use dropshot::HttpResponseOk; use dropshot::Path; use dropshot::Query; @@ -52,6 +54,7 @@ fn demo_api() -> ApiDescription { api.register(demo_handler_path_param_uuid).unwrap(); api.register(demo_handler_path_param_u32).unwrap(); api.register(demo_handler_untyped_body).unwrap(); + api.register(demo_handler_delete).unwrap(); /* * We don't need to exhaustively test these cases, as they're tested by unit @@ -602,6 +605,20 @@ async fn test_untyped_body() { testctx.teardown().await; } +/* + * Test delete request + */ +#[tokio::test] +async fn test_delete_request() { + let api = demo_api(); + let testctx = common::test_setup("test_delete_request", api); + let client = &testctx.client_testctx; + + object_delete::<()>(&client, "/testing/delete").await; + + testctx.teardown().await; +} + /* * Demo handler functions */ @@ -765,6 +782,16 @@ async fn demo_handler_path_param_impossible( http_echo(&path_params.into_inner()) } +#[endpoint { + method = DELETE, + path = "/testing/delete", +}] +async fn demo_handler_delete( + _rqctx: RequestCtx, +) -> Result { + Ok(HttpResponseDeleted()) +} + fn http_echo(t: &T) -> Result, HttpError> { Ok(Response::builder() .header(http::header::CONTENT_TYPE, CONTENT_TYPE_JSON) From eea9dd1e0daf42f13fb4ff97f3ee59c087612a9b Mon Sep 17 00:00:00 2001 From: Tess Eisenberger Date: Tue, 12 Oct 2021 18:22:16 -0700 Subject: [PATCH 2/4] Run cargo fmt --- dropshot/tests/test_demo.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dropshot/tests/test_demo.rs b/dropshot/tests/test_demo.rs index a433987ac..f2e8b294d 100644 --- a/dropshot/tests/test_demo.rs +++ b/dropshot/tests/test_demo.rs @@ -16,9 +16,9 @@ */ use dropshot::endpoint; +use dropshot::test_util::object_delete; use dropshot::test_util::read_json; use dropshot::test_util::read_string; -use dropshot::test_util::object_delete; use dropshot::ApiDescription; use dropshot::HttpError; use dropshot::HttpResponseDeleted; From dbaa1b413a6d1c63c2e967375011c71f9e000b30 Mon Sep 17 00:00:00 2001 From: Tess Eisenberger Date: Wed, 13 Oct 2021 10:12:55 -0700 Subject: [PATCH 3/4] correct response code and use make_request_no_body --- dropshot/src/test_util.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/dropshot/src/test_util.rs b/dropshot/src/test_util.rs index 5b45620c0..a5d0e64a3 100644 --- a/dropshot/src/test_util.rs +++ b/dropshot/src/test_util.rs @@ -619,17 +619,15 @@ pub async fn objects_post( pub async fn object_delete( client: &ClientTestContext, object_url: &str, -) -> T { - let mut response = client - .make_request_with_body( +) { + client + .make_request_no_body( Method::DELETE, &object_url, - "".into(), - StatusCode::OK, + StatusCode::NO_CONTENT, ) .await .unwrap(); - read_json::(&mut response).await } /** From 2084f4f2da369470571bdd7e50ec19b7367b5ef4 Mon Sep 17 00:00:00 2001 From: Tess Eisenberger Date: Wed, 13 Oct 2021 10:59:40 -0700 Subject: [PATCH 4/4] remove unnused generic --- dropshot/src/test_util.rs | 5 +---- dropshot/tests/test_demo.rs | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/dropshot/src/test_util.rs b/dropshot/src/test_util.rs index a5d0e64a3..1c238cf45 100644 --- a/dropshot/src/test_util.rs +++ b/dropshot/src/test_util.rs @@ -616,10 +616,7 @@ pub async fn objects_post( /** * Issues an HTTP DELETE to the specified object URL to delete an object. */ -pub async fn object_delete( - client: &ClientTestContext, - object_url: &str, -) { +pub async fn object_delete(client: &ClientTestContext, object_url: &str) { client .make_request_no_body( Method::DELETE, diff --git a/dropshot/tests/test_demo.rs b/dropshot/tests/test_demo.rs index f2e8b294d..c5d2bce2d 100644 --- a/dropshot/tests/test_demo.rs +++ b/dropshot/tests/test_demo.rs @@ -614,7 +614,7 @@ async fn test_delete_request() { let testctx = common::test_setup("test_delete_request", api); let client = &testctx.client_testctx; - object_delete::<()>(&client, "/testing/delete").await; + object_delete(&client, "/testing/delete").await; testctx.teardown().await; }