diff options
Diffstat (limited to 'third_party/rust/warp/tests/redirect.rs')
-rw-r--r-- | third_party/rust/warp/tests/redirect.rs | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/third_party/rust/warp/tests/redirect.rs b/third_party/rust/warp/tests/redirect.rs new file mode 100644 index 0000000000..be7fd33e4a --- /dev/null +++ b/third_party/rust/warp/tests/redirect.rs @@ -0,0 +1,57 @@ +#![deny(warnings)] +use warp::{http::Uri, Filter}; + +#[tokio::test] +async fn redirect_uri() { + let over_there = warp::any().map(|| warp::redirect(Uri::from_static("/over-there"))); + + let req = warp::test::request(); + let resp = req.reply(&over_there).await; + + assert_eq!(resp.status(), 301); + assert_eq!(resp.headers()["location"], "/over-there"); +} + +#[tokio::test] +async fn redirect_found_uri() { + let over_there = warp::any().map(|| warp::redirect::found(Uri::from_static("/over-there"))); + + let req = warp::test::request(); + let resp = req.reply(&over_there).await; + + assert_eq!(resp.status(), 302); + assert_eq!(resp.headers()["location"], "/over-there"); +} + +#[tokio::test] +async fn redirect_see_other_uri() { + let over_there = warp::any().map(|| warp::redirect::see_other(Uri::from_static("/over-there"))); + + let req = warp::test::request(); + let resp = req.reply(&over_there).await; + + assert_eq!(resp.status(), 303); + assert_eq!(resp.headers()["location"], "/over-there"); +} + +#[tokio::test] +async fn redirect_temporary_uri() { + let over_there = warp::any().map(|| warp::redirect::temporary(Uri::from_static("/over-there"))); + + let req = warp::test::request(); + let resp = req.reply(&over_there).await; + + assert_eq!(resp.status(), 307); + assert_eq!(resp.headers()["location"], "/over-there"); +} + +#[tokio::test] +async fn redirect_permanent_uri() { + let over_there = warp::any().map(|| warp::redirect::permanent(Uri::from_static("/over-there"))); + + let req = warp::test::request(); + let resp = req.reply(&over_there).await; + + assert_eq!(resp.status(), 308); + assert_eq!(resp.headers()["location"], "/over-there"); +} |