mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-27 00:00:24 +02:00
Use IntoFuture for test RequestBuilder (#2470)
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user