mirror of
https://github.com/actix/actix-extras.git
synced 2024-12-01 02:44:37 +01:00
add session test
This commit is contained in:
parent
3623383e83
commit
58079b5bbe
@ -247,7 +247,7 @@ impl<I, E> Reply<I, E> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub(crate) fn as_msg(&self) -> &I {
|
pub(crate) fn as_msg(&self) -> &I {
|
||||||
match self.0.as_ref().unwrap() {
|
match self.0.as_ref().unwrap() {
|
||||||
ReplyResult::Ok(ref resp) => resp,
|
&ReplyResult::Ok(ref resp) => resp,
|
||||||
_ => panic!(),
|
_ => panic!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -255,7 +255,7 @@ impl<I, E> Reply<I, E> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub(crate) fn as_err(&self) -> Option<&E> {
|
pub(crate) fn as_err(&self) -> Option<&E> {
|
||||||
match self.0.as_ref().unwrap() {
|
match self.0.as_ref().unwrap() {
|
||||||
ReplyResult::Err(ref err) => Some(err),
|
&ReplyResult::Err(ref err) => Some(err),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
//! use actix_web::{server, App, HttpRequest, Result};
|
//! use actix_web::{server, App, HttpRequest, Result};
|
||||||
//! use actix_web::middleware::session::{RequestSession, SessionStorage, CookieSessionBackend};
|
//! 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
|
//! // access session data
|
||||||
//! if let Some(count) = req.session().get::<i32>("counter")? {
|
//! if let Some(count) = req.session().get::<i32>("counter")? {
|
||||||
//! println!("SESSION value: {}", count);
|
//! 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user