Debian Codegraph @

third_party/rust/warp/tests/redirect.rs

raw
1 #![deny(warnings)]
2 use warp::{http::Uri, Filter};
3
4 #[tokio::test]
5 async fn redirect_uri() {
6 let over_there = warp::any().map(|| warp::redirect(Uri::from_static("/over-there")));
7
8 let req = warp::test::request();
9 let resp = req.reply(&over_there).await;
10
11 assert_eq!(resp.status(), 301);
12 assert_eq!(resp.headers()["location"], "/over-there");
13 }
14
15 #[tokio::test]
16 async fn redirect_found_uri() {
17 let over_there = warp::any().map(|| warp::redirect::found(Uri::from_static("/over-there")));
18
19 let req = warp::test::request();
20 let resp = req.reply(&over_there).await;
21
22 assert_eq!(resp.status(), 302);
23 assert_eq!(resp.headers()["location"], "/over-there");
24 }
25
26 #[tokio::test]
27 async fn redirect_see_other_uri() {
28 let over_there = warp::any().map(|| warp::redirect::see_other(Uri::from_static("/over-there")));
29
30 let req = warp::test::request();
31 let resp = req.reply(&over_there).await;
32
33 assert_eq!(resp.status(), 303);
34 assert_eq!(resp.headers()["location"], "/over-there");
35 }
36
37 #[tokio::test]
38 async fn redirect_temporary_uri() {
39 let over_there = warp::any().map(|| warp::redirect::temporary(Uri::from_static("/over-there")));
40
41 let req = warp::test::request();
42 let resp = req.reply(&over_there).await;
43
44 assert_eq!(resp.status(), 307);
45 assert_eq!(resp.headers()["location"], "/over-there");
46 }
47
48 #[tokio::test]
49 async fn redirect_permanent_uri() {
50 let over_there = warp::any().map(|| warp::redirect::permanent(Uri::from_static("/over-there")));
51
52 let req = warp::test::request();
53 let resp = req.reply(&over_there).await;
54
55 assert_eq!(resp.status(), 308);
56 assert_eq!(resp.headers()["location"], "/over-there");
57 }