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:
David Pedersen
2021-09-19 09:38:34 +00:00
committed by GitHub
parent 2a683417d1
commit 0b9e0c7508
7 changed files with 338 additions and 645 deletions
+3 -10
View File
@@ -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"
);
}
+5 -12
View File
@@ -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");
}
}