Skip to main content

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-nil UsersStore instance with initialized store and stLock fields.
  • Parameters:
    • t: *testing.T - The testing object.
  • Returns: None

TestUsersAddAndGet(t *testing.T)

  • Purpose: Tests the Add and Get methods of the UsersStore 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 the User 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-nil Session instance with the initial status set to SessionStatusPending.
  • Parameters:
    • t: *testing.T - The testing object.
  • Returns: None

TestSessionIsActive(t *testing.T)

  • Purpose: Tests the IsActive method of the Session type to ensure it correctly determines if a session is active based on its status and updates the LastAccessedAt timestamp.
  • Parameters:
    • t: *testing.T - The testing object.
  • Returns: None

TestSessionActivate(t *testing.T)

  • Purpose: Tests the Activate method of the Session type to ensure it correctly sets the session status to SessionStatusActive 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 the Session 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 the Session type to ensure it correctly sets the session status to SessionStatusExpired.
  • Parameters:
    • t: *testing.T - The testing object.
  • Returns: None

Code Examples

None

Getting Started Relevance

NO