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
+8 -32
View File
@@ -48,15 +48,9 @@ async fn handler() {
.handle_error(|_: BoxError| Ok::<_, Infallible>(StatusCode::REQUEST_TIMEOUT))),
);
let addr = run_in_background(app).await;
let client = TestClient::new(app);
let client = reqwest::Client::new();
let res = client
.get(format!("http://{}/", addr))
.send()
.await
.unwrap();
let res = client.get("/").send().await;
assert_eq!(res.status(), StatusCode::REQUEST_TIMEOUT);
}
@@ -70,15 +64,9 @@ async fn handler_multiple_methods_first() {
.post(unit),
);
let addr = run_in_background(app).await;
let client = TestClient::new(app);
let client = reqwest::Client::new();
let res = client
.get(format!("http://{}/", addr))
.send()
.await
.unwrap();
let res = client.get("/").send().await;
assert_eq!(res.status(), StatusCode::REQUEST_TIMEOUT);
}
@@ -95,15 +83,9 @@ async fn handler_multiple_methods_middle() {
.post(unit),
);
let addr = run_in_background(app).await;
let client = TestClient::new(app);
let client = reqwest::Client::new();
let res = client
.get(format!("http://{}/", addr))
.send()
.await
.unwrap();
let res = client.get("/").send().await;
assert_eq!(res.status(), StatusCode::REQUEST_TIMEOUT);
}
@@ -118,15 +100,9 @@ async fn handler_multiple_methods_last() {
),
);
let addr = run_in_background(app).await;
let client = TestClient::new(app);
let client = reqwest::Client::new();
let res = client
.get(format!("http://{}/", addr))
.send()
.await
.unwrap();
let res = client.get("/").send().await;
assert_eq!(res.status(), StatusCode::REQUEST_TIMEOUT);
}