From 1970c99522ef37d4a5fbed404b9b100912fad69a Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Sun, 24 Mar 2019 20:21:20 -0700 Subject: [PATCH] add session test --- actix-session/src/lib.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/actix-session/src/lib.rs b/actix-session/src/lib.rs index 1dd367ba..ae0fd23c 100644 --- a/actix-session/src/lib.rs +++ b/actix-session/src/lib.rs @@ -181,3 +181,30 @@ impl

FromRequest

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::("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())]); + } +}