2017-04-20 20:43:01 +00:00
|
|
|
use super::rocket;
|
2017-06-06 20:41:04 +00:00
|
|
|
use rocket::local::Client;
|
2017-04-20 20:43:01 +00:00
|
|
|
|
|
|
|
#[test]
|
2017-05-15 04:46:01 +00:00
|
|
|
fn rewrite_get_put() {
|
2017-06-06 20:41:04 +00:00
|
|
|
let client = Client::new(rocket()).unwrap();
|
|
|
|
let mut response = client.get("/").dispatch();
|
2019-08-04 22:29:47 +00:00
|
|
|
assert_eq!(response.body_string_wait(), Some("Hello, fairings!".into()));
|
2017-04-20 20:43:01 +00:00
|
|
|
}
|
2017-05-17 08:39:36 +00:00
|
|
|
|
2017-05-15 04:46:01 +00:00
|
|
|
#[test]
|
|
|
|
fn counts() {
|
2017-06-06 20:41:04 +00:00
|
|
|
let client = Client::new(rocket()).unwrap();
|
2017-05-15 04:46:01 +00:00
|
|
|
|
|
|
|
// Issue 1 GET request.
|
2017-06-06 20:41:04 +00:00
|
|
|
client.get("/").dispatch();
|
2017-05-15 04:46:01 +00:00
|
|
|
|
|
|
|
// Check the GET count, taking into account _this_ GET request.
|
2017-06-06 20:41:04 +00:00
|
|
|
let mut response = client.get("/counts").dispatch();
|
2019-08-04 22:29:47 +00:00
|
|
|
assert_eq!(response.body_string_wait(), Some("Get: 2\nPost: 0".into()));
|
2017-05-15 04:46:01 +00:00
|
|
|
|
|
|
|
// Issue 1 more GET request and a POST.
|
2017-06-06 20:41:04 +00:00
|
|
|
client.get("/").dispatch();
|
|
|
|
client.post("/").dispatch();
|
2017-05-15 04:46:01 +00:00
|
|
|
|
|
|
|
// Check the counts.
|
2017-06-06 20:41:04 +00:00
|
|
|
let mut response = client.get("/counts").dispatch();
|
2019-08-04 22:29:47 +00:00
|
|
|
assert_eq!(response.body_string_wait(), Some("Get: 4\nPost: 1".into()));
|
2017-05-15 04:46:01 +00:00
|
|
|
}
|
2017-05-17 08:39:36 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn token() {
|
2017-06-06 20:41:04 +00:00
|
|
|
let client = Client::new(rocket()).unwrap();
|
2017-05-17 08:39:36 +00:00
|
|
|
|
|
|
|
// Ensure the token is '123', which is what we have in `Rocket.toml`.
|
2017-06-06 20:41:04 +00:00
|
|
|
let mut res = client.get("/token").dispatch();
|
2019-08-04 22:29:47 +00:00
|
|
|
assert_eq!(res.body_string_wait(), Some("123".into()));
|
2017-05-17 08:39:36 +00:00
|
|
|
}
|