1
0
Fork 0
mirror of https://github.com/tokio-rs/axum.git synced 2025-03-22 23:15:31 +01:00

Change TestClient to not follow redirects ()

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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 11 deletions
axum/src

View file

@ -321,9 +321,9 @@ async fn with_trailing_slash() {
let client = TestClient::new(app);
// `TestClient` automatically follows redirects
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]
@ -332,9 +332,9 @@ async fn without_trailing_slash() {
let client = TestClient::new(app);
// `TestClient` automatically follows redirects
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]
@ -363,7 +363,8 @@ async fn with_trailing_slash_post() {
// `TestClient` automatically follows redirects
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
@ -373,9 +374,9 @@ async fn without_trailing_slash_post() {
let client = TestClient::new(app);
// `TestClient` automatically follows redirects
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

View file

@ -45,10 +45,12 @@ impl TestClient {
server.await.expect("server error");
});
TestClient {
client: reqwest::Client::new(),
addr,
}
let client = reqwest::Client::builder()
.redirect(reqwest::redirect::Policy::none())
.build()
.unwrap();
TestClient { client, addr }
}
pub(crate) fn get(&self, url: &str) -> RequestBuilder {