mirror of
https://github.com/actix/actix-web.git
synced 2024-12-20 23:26:44 +00:00
add session test
This commit is contained in:
parent
51e4dcf3b3
commit
1970c99522
1 changed files with 27 additions and 0 deletions
|
@ -181,3 +181,30 @@ impl<P> FromRequest<P> for Session {
|
|||
Ok(Session::get_session(req))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use actix_web::{test, HttpResponse};
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn session() {
|
||||
let mut req = test::TestRequest::default().to_service();
|
||||
|
||||
Session::set_session(
|
||||
vec![("key".to_string(), "\"value\"".to_string())].into_iter(),
|
||||
&mut req,
|
||||
);
|
||||
let session = Session::get_session(&mut req);
|
||||
let res = session.get::<String>("key").unwrap();
|
||||
assert_eq!(res, Some("value".to_string()));
|
||||
|
||||
session.set("key2", "value2".to_string()).unwrap();
|
||||
session.remove("key");
|
||||
|
||||
let mut res = req.into_response(HttpResponse::Ok().finish());
|
||||
let changes: Vec<_> = Session::get_changes(&mut res).unwrap().collect();
|
||||
assert_eq!(changes, [("key2".to_string(), "\"value2\"".to_string())]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue