diff --git a/core/lib/tests/untracked-vs-tracked.rs b/core/lib/tests/untracked-vs-tracked.rs new file mode 100644 index 00000000..05b9ae5e --- /dev/null +++ b/core/lib/tests/untracked-vs-tracked.rs @@ -0,0 +1,45 @@ +#[macro_use] extern crate rocket; + +use rocket::http::{Cookie, CookieJar}; + +#[post("/")] +fn add(jar: &CookieJar<'_>) { + jar.add(Cookie::new("name", "value")); +} + +#[get("/")] +fn get<'a>(jar: &'a CookieJar<'_>) -> Option<&'a str> { + jar.get("name").map(|c| c.value()) +} + +#[cfg(test)] +mod many_cookie_jars_tests { + use super::*; + use rocket::local::blocking::Client; + use rocket::http::Status; + + fn rocket() -> rocket::Rocket { + rocket::ignite().mount("/", routes![add, get]) + } + + #[test] + fn test_tracked() { + let client = Client::tracked(rocket()).unwrap(); + + assert_eq!(client.get("/").dispatch().status(), Status::NotFound); + assert_eq!(client.post("/").dispatch().status(), Status::Ok); + + let response = client.get("/").dispatch(); + assert_eq!(response.status(), Status::Ok); + assert_eq!(response.into_string().unwrap(), "value"); + } + + #[test] + fn test_untracked() { + let client = Client::untracked(rocket()).unwrap(); + + assert_eq!(client.get("/").dispatch().status(), Status::NotFound); + assert_eq!(client.post("/").dispatch().status(), Status::Ok); + assert_eq!(client.get("/").dispatch().status(), Status::NotFound); + } +}