session_test.go
session_test.go - Overview
This file contains unit tests for the auth
package, specifically focusing on the UsersStore
, User
, and Session
types and their associated methods. It tests functionalities such as creating users, setting passwords, creating sessions, activating sessions, validating sessions, and expiring sessions.
Detailed Documentation
TestNewUsers(t *testing.T)
- Purpose: Tests the
NewUsersStore
function to ensure it returns a non-nilUsersStore
instance with initializedstore
andstLock
fields. - Parameters:
t
:*testing.T
- The testing object.
- Returns: None
TestUsersAddAndGet(t *testing.T)
- Purpose: Tests the
Add
andGet
methods of theUsersStore
to ensure that a user can be added and retrieved correctly. - Parameters:
t
:*testing.T
- The testing object.
- Returns: None
TestUserSetPassword(t *testing.T)
- Purpose: Tests the
SetPassword
method of theUser
type to ensure that a password can be set and stored correctly. - Parameters:
t
:*testing.T
- The testing object.
- Returns: None
TestNewSession(t *testing.T)
- Purpose: Tests the
NewSession
function to ensure it returns a non-nilSession
instance with the initial status set toSessionStatusPending
. - Parameters:
t
:*testing.T
- The testing object.
- Returns: None
TestSessionIsActive(t *testing.T)
- Purpose: Tests the
IsActive
method of theSession
type to ensure it correctly determines if a session is active based on its status and updates theLastAccessedAt
timestamp. - Parameters:
t
:*testing.T
- The testing object.
- Returns: None
TestSessionActivate(t *testing.T)
- Purpose: Tests the
Activate
method of theSession
type to ensure it correctly sets the session status toSessionStatusActive
and associates the session with a user. - Parameters:
t
:*testing.T
- The testing object.
- Returns: None
TestSessionValidate(t *testing.T)
- Purpose: Tests the
Validate
method of theSession
type to ensure it correctly validates a user's credentials and activates the session upon successful validation. - Parameters:
t
:*testing.T
- The testing object.
- Returns: None
TestSessionExpire(t *testing.T)
- Purpose: Tests the
Expire
method of theSession
type to ensure it correctly sets the session status toSessionStatusExpired
. - Parameters:
t
:*testing.T
- The testing object.
- Returns: None
Code Examples
None
Getting Started Relevance
NO