Change TestClient to not follow redirects (#715)

Makes it more obvious what actually goes on
This commit is contained in:
David Pedersen
2022-01-21 17:32:12 +01:00
committed by GitHub
parent 50f42d8071
commit 830bfdbe3c
2 changed files with 14 additions and 11 deletions
+8 -7
View File
@@ -321,9 +321,9 @@ async fn with_trailing_slash() {
let client = TestClient::new(app); let client = TestClient::new(app);
// `TestClient` automatically follows redirects
let res = client.get("/foo/").send().await; let res = client.get("/foo/").send().await;
assert_eq!(res.status(), StatusCode::OK); assert_eq!(res.status(), StatusCode::PERMANENT_REDIRECT);
assert_eq!(res.headers().get("location").unwrap(), "/foo");
} }
#[tokio::test] #[tokio::test]
@@ -332,9 +332,9 @@ async fn without_trailing_slash() {
let client = TestClient::new(app); let client = TestClient::new(app);
// `TestClient` automatically follows redirects
let res = client.get("/foo").send().await; let res = client.get("/foo").send().await;
assert_eq!(res.status(), StatusCode::OK); assert_eq!(res.status(), StatusCode::PERMANENT_REDIRECT);
assert_eq!(res.headers().get("location").unwrap(), "/foo/");
} }
#[tokio::test] #[tokio::test]
@@ -363,7 +363,8 @@ async fn with_trailing_slash_post() {
// `TestClient` automatically follows redirects // `TestClient` automatically follows redirects
let res = client.post("/foo/").send().await; let res = client.post("/foo/").send().await;
assert_eq!(res.status(), StatusCode::OK); assert_eq!(res.status(), StatusCode::PERMANENT_REDIRECT);
assert_eq!(res.headers().get("location").unwrap(), "/foo");
} }
// for https://github.com/tokio-rs/axum/issues/681 // for https://github.com/tokio-rs/axum/issues/681
@@ -373,9 +374,9 @@ async fn without_trailing_slash_post() {
let client = TestClient::new(app); let client = TestClient::new(app);
// `TestClient` automatically follows redirects
let res = client.post("/foo").send().await; let res = client.post("/foo").send().await;
assert_eq!(res.status(), StatusCode::OK); assert_eq!(res.status(), StatusCode::PERMANENT_REDIRECT);
assert_eq!(res.headers().get("location").unwrap(), "/foo/");
} }
// for https://github.com/tokio-rs/axum/issues/420 // for https://github.com/tokio-rs/axum/issues/420
+6 -4
View File
@@ -45,10 +45,12 @@ impl TestClient {
server.await.expect("server error"); server.await.expect("server error");
}); });
TestClient { let client = reqwest::Client::builder()
client: reqwest::Client::new(), .redirect(reqwest::redirect::Policy::none())
addr, .build()
} .unwrap();
TestClient { client, addr }
} }
pub(crate) fn get(&self, url: &str) -> RequestBuilder { pub(crate) fn get(&self, url: &str) -> RequestBuilder {