diff --git a/dropshot/src/test_util.rs b/dropshot/src/test_util.rs index 3c41b3830..1c238cf45 100644 --- a/dropshot/src/test_util.rs +++ b/dropshot/src/test_util.rs @@ -613,6 +613,20 @@ 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) { + client + .make_request_no_body( + Method::DELETE, + &object_url, + StatusCode::NO_CONTENT, + ) + .await + .unwrap(); +} + /** * Iterate a paginated collection. */ diff --git a/dropshot/tests/test_demo.rs b/dropshot/tests/test_demo.rs index d32d85d1a..c5d2bce2d 100644 --- a/dropshot/tests/test_demo.rs +++ b/dropshot/tests/test_demo.rs @@ -16,10 +16,12 @@ */ use dropshot::endpoint; +use dropshot::test_util::object_delete; use dropshot::test_util::read_json; use dropshot::test_util::read_string; 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)