Skip to content

Add testing helper for DELETE requests #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions dropshot/src/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,20 @@ pub async fn objects_post<S: Serialize + Debug, T: DeserializeOwned>(
read_json::<T>(&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.
*/
Expand Down
27 changes: 27 additions & 0 deletions dropshot/tests/test_demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -52,6 +54,7 @@ fn demo_api() -> ApiDescription<usize> {
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
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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<HttpResponseDeleted, HttpError> {
Ok(HttpResponseDeleted())
}

fn http_echo<T: Serialize>(t: &T) -> Result<Response<Body>, HttpError> {
Ok(Response::builder()
.header(http::header::CONTENT_TYPE, CONTENT_TYPE_JSON)
Expand Down