mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-25 00:00:23 +02:00
Refactor internal testing setup (#338)
This changes the test setup to use our own client rather than using reqwest directly. Allows us to add several quality of life features like always unwrapping results.
This commit is contained in:
@@ -335,19 +335,12 @@ mod tests {
|
||||
|
||||
let app = Router::new().route("/", post(handler));
|
||||
|
||||
let addr = run_in_background(app).await;
|
||||
let client = TestClient::new(app);
|
||||
|
||||
let client = reqwest::Client::new();
|
||||
|
||||
let res = client
|
||||
.post(format!("http://{}", addr))
|
||||
.body("hi there")
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
let res = client.post("/").body("hi there").send().await;
|
||||
assert_eq!(res.status(), StatusCode::INTERNAL_SERVER_ERROR);
|
||||
assert_eq!(
|
||||
res.text().await.unwrap(),
|
||||
res.text().await,
|
||||
"Cannot have two request body extractors for a single handler"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -152,21 +152,14 @@ mod tests {
|
||||
|
||||
let app = Router::new().route("/", get(handle));
|
||||
|
||||
let addr = run_in_background(app).await;
|
||||
let client = TestClient::new(app);
|
||||
|
||||
let client = reqwest::Client::new();
|
||||
|
||||
let res = client
|
||||
.get(format!("http://{}", addr))
|
||||
.header("user-agent", "foobar")
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
let body = res.text().await.unwrap();
|
||||
let res = client.get("/").header("user-agent", "foobar").send().await;
|
||||
let body = res.text().await;
|
||||
assert_eq!(body, "foobar");
|
||||
|
||||
let res = client.get(format!("http://{}", addr)).send().await.unwrap();
|
||||
let body = res.text().await.unwrap();
|
||||
let res = client.get("/").send().await;
|
||||
let body = res.text().await;
|
||||
assert_eq!(body, "Header of type `user-agent` was missing");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user