1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-11-03 15:39:50 +00:00

add session test

This commit is contained in:
Nikolay Kim 2018-05-02 19:11:44 -07:00
parent 3623383e83
commit 58079b5bbe
2 changed files with 30 additions and 3 deletions

View file

@ -247,7 +247,7 @@ impl<I, E> Reply<I, E> {
#[cfg(test)]
pub(crate) fn as_msg(&self) -> &I {
match self.0.as_ref().unwrap() {
ReplyResult::Ok(ref resp) => resp,
&ReplyResult::Ok(ref resp) => resp,
_ => panic!(),
}
}
@ -255,7 +255,7 @@ impl<I, E> Reply<I, E> {
#[cfg(test)]
pub(crate) fn as_err(&self) -> Option<&E> {
match self.0.as_ref().unwrap() {
ReplyResult::Err(ref err) => Some(err),
&ReplyResult::Err(ref err) => Some(err),
_ => None,
}
}

View file

@ -37,7 +37,7 @@
//! use actix_web::{server, App, HttpRequest, Result};
//! use actix_web::middleware::session::{RequestSession, SessionStorage, CookieSessionBackend};
//!
//! fn index(mut req: HttpRequest) -> Result<&'static str> {
//! fn index(req: HttpRequest) -> Result<&'static str> {
//! // access session data
//! if let Some(count) = req.session().get::<i32>("counter")? {
//! println!("SESSION value: {}", count);
@ -525,3 +525,30 @@ impl<S> SessionBackend<S> for CookieSessionBackend {
})
}
}
#[cfg(test)]
mod tests {
use super::*;
use application::App;
use test;
#[test]
fn cookie_session() {
let mut srv = test::TestServer::with_factory(|| {
App::new()
.middleware(SessionStorage::new(
CookieSessionBackend::signed(&[0; 32]).secure(false),
))
.resource("/", |r| {
r.f(|req| {
let _ = req.session().set("counter", 100);
"test"
})
})
});
let request = srv.get().uri(srv.url("/")).finish().unwrap();
let response = srv.execute(request.send()).unwrap();
assert!(response.cookie("actix-session").is_some());
}
}