Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added function to create an empty session for testing #253

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion actix-session/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changes

## Unreleased - 2021-xx-xx
## Unreleased - 2022-xx-xx
- Add an `empty()` function to `Session` for simple testing. [#253]

[#253]: https://github.com/actix/actix-extras/pull/253


## 0.7.0 - 2022-07-09
Expand Down
11 changes: 11 additions & 0 deletions actix-session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ struct SessionInner {
}

impl Session {
/// Create an empty session. Appropriate for testing.
///
/// This session wraps an empty state map and status. It can be instantiated for testing purposes.
pub fn empty() -> Session {
let inner = SessionInner {
state: HashMap::new(),
status: SessionStatus::default(),
};
Session(Rc::new(RefCell::new(inner)))
}

/// Get a `value` from the session.
///
/// It returns an error if it fails to deserialize as `T` the JSON value associated with `key`.
Expand Down