Skip to content

Commit 928da85

Browse files
authored
Add testing helper for DELETE requests (#136)
This introduces test_util.object_delete(), to go along with the existing test_util helpers.
1 parent 4009918 commit 928da85

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

dropshot/src/test_util.rs

+14
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,20 @@ pub async fn objects_post<S: Serialize + Debug, T: DeserializeOwned>(
613613
read_json::<T>(&mut response).await
614614
}
615615

616+
/**
617+
* Issues an HTTP DELETE to the specified object URL to delete an object.
618+
*/
619+
pub async fn object_delete(client: &ClientTestContext, object_url: &str) {
620+
client
621+
.make_request_no_body(
622+
Method::DELETE,
623+
&object_url,
624+
StatusCode::NO_CONTENT,
625+
)
626+
.await
627+
.unwrap();
628+
}
629+
616630
/**
617631
* Iterate a paginated collection.
618632
*/

dropshot/tests/test_demo.rs

+27
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
*/
1717

1818
use dropshot::endpoint;
19+
use dropshot::test_util::object_delete;
1920
use dropshot::test_util::read_json;
2021
use dropshot::test_util::read_string;
2122
use dropshot::ApiDescription;
2223
use dropshot::HttpError;
24+
use dropshot::HttpResponseDeleted;
2325
use dropshot::HttpResponseOk;
2426
use dropshot::Path;
2527
use dropshot::Query;
@@ -52,6 +54,7 @@ fn demo_api() -> ApiDescription<usize> {
5254
api.register(demo_handler_path_param_uuid).unwrap();
5355
api.register(demo_handler_path_param_u32).unwrap();
5456
api.register(demo_handler_untyped_body).unwrap();
57+
api.register(demo_handler_delete).unwrap();
5558

5659
/*
5760
* We don't need to exhaustively test these cases, as they're tested by unit
@@ -602,6 +605,20 @@ async fn test_untyped_body() {
602605
testctx.teardown().await;
603606
}
604607

608+
/*
609+
* Test delete request
610+
*/
611+
#[tokio::test]
612+
async fn test_delete_request() {
613+
let api = demo_api();
614+
let testctx = common::test_setup("test_delete_request", api);
615+
let client = &testctx.client_testctx;
616+
617+
object_delete(&client, "/testing/delete").await;
618+
619+
testctx.teardown().await;
620+
}
621+
605622
/*
606623
* Demo handler functions
607624
*/
@@ -765,6 +782,16 @@ async fn demo_handler_path_param_impossible(
765782
http_echo(&path_params.into_inner())
766783
}
767784

785+
#[endpoint {
786+
method = DELETE,
787+
path = "/testing/delete",
788+
}]
789+
async fn demo_handler_delete(
790+
_rqctx: RequestCtx,
791+
) -> Result<HttpResponseDeleted, HttpError> {
792+
Ok(HttpResponseDeleted())
793+
}
794+
768795
fn http_echo<T: Serialize>(t: &T) -> Result<Response<Body>, HttpError> {
769796
Ok(Response::builder()
770797
.header(http::header::CONTENT_TYPE, CONTENT_TYPE_JSON)

0 commit comments

Comments
 (0)