Use IntoFuture for test RequestBuilder (#2470)

This commit is contained in:
David Pedersen
2023-12-30 18:23:53 +01:00
committed by GitHub
parent 3b43b257e7
commit 7ea7e9f618
32 changed files with 289 additions and 351 deletions
+5 -20
View File
@@ -245,7 +245,7 @@ mod tests {
let app = Router::new().route("/", post(handler));
let client = TestClient::new(app);
let res = client.post("/").json(&json!({ "foo": "bar" })).send().await;
let res = client.post("/").json(&json!({ "foo": "bar" })).await;
let body = res.text().await;
assert_eq!(body, "bar");
@@ -277,11 +277,7 @@ mod tests {
let client = TestClient::new(app);
// The escaped characters prevent serde_json from borrowing.
let res = client
.post("/")
.json(&json!({ "foo": "\"bar\"" }))
.send()
.await;
let res = client.post("/").json(&json!({ "foo": "\"bar\"" })).await;
let body = res.text().await;
@@ -308,19 +304,11 @@ mod tests {
let client = TestClient::new(app);
let res = client
.post("/")
.json(&json!({ "foo": "good" }))
.send()
.await;
let res = client.post("/").json(&json!({ "foo": "good" })).await;
let body = res.text().await;
assert_eq!(body, "good");
let res = client
.post("/")
.json(&json!({ "foo": "\"bad\"" }))
.send()
.await;
let res = client.post("/").json(&json!({ "foo": "\"bad\"" })).await;
assert_eq!(res.status(), StatusCode::UNPROCESSABLE_ENTITY);
let body_text = res.text().await;
assert_eq!(
@@ -344,7 +332,7 @@ mod tests {
let app = Router::new().route("/", post(handler));
let client = TestClient::new(app);
let res = client.post("/").body(r#"{ "foo": "bar" }"#).send().await;
let res = client.post("/").body(r#"{ "foo": "bar" }"#).await;
let status = res.status();
@@ -366,7 +354,6 @@ mod tests {
.post("/")
.header("content-type", content_type)
.body("{}")
.send()
.await;
res.status() == StatusCode::OK
@@ -395,7 +382,6 @@ mod tests {
.post("/")
.body("{")
.header("content-type", "application/json")
.send()
.await;
assert_eq!(res.status(), StatusCode::BAD_REQUEST);
@@ -433,7 +419,6 @@ mod tests {
.post("/")
.body("{\"a\": 1, \"b\": [{\"x\": 2}]}")
.header("content-type", "application/json")
.send()
.await;
assert_eq!(res.status(), StatusCode::UNPROCESSABLE_ENTITY);