mutablesession_test.go

Overview

The mutablesession_test.go file contains unit tests for the MutableSession type provided by the sessioninternal package. This file validates the core functionality of mutable session objects, which represent user sessions capable of storing and modifying arbitrary key-value state data. These tests ensure the correctness of session state mutation, retrieval, and the passthrough of session metadata methods.

This test suite interacts primarily with:

The file's tests verify:

Detailed Explanations

Helper Function: createMutableSession

func createMutableSession(ctx context.Context, t *testing.T, sessionID string, initialData map[string]any) (*sessioninternal.MutableSession, session.Service)

Test: TestMutableSession_SetGet

func TestMutableSession_SetGet(t *testing.T)

Test: TestMutableSession_All

func TestMutableSession_All(t *testing.T)

Test: TestMutableSession_PassthroughMethods

func TestMutableSession_PassthroughMethods(t *testing.T)

Important Implementation Details


Interaction with Other Components

This file is part of the broader session management system described in Session Management, focusing on verifying mutable session behavior.


Structure Diagram

flowchart TD
A[createMutableSession] --> B[session.InMemoryService]
A --> C[session.CreateRequest]
A --> D[sessioninternal.NewMutableSession]
subgraph TestMutableSession_SetGet
E[MutableSession.Set]
F[MutableSession.Get]
end
subgraph TestMutableSession_All
G[MutableSession.All]
H[maps.Collect]
end
subgraph TestMutableSession_PassthroughMethods
I[MutableSession.ID]
J[MutableSession.AppName]
K[MutableSession.UserID]
L[MutableSession.LastUpdateTime]
M[MutableSession.Events]
N[MutableSession.State]
end
D --> E
D --> F
D --> G
D --> I
D --> J
D --> K
D --> L
D --> M
D --> N

Summary of Key Functions and Methods

Function/Method

Description

Parameters

Returns

createMutableSession

Helper to create a mutable session with initial state

context, testing.T, sessionID, initial map

*MutableSession, Service

(MutableSession).Set

Sets a key-value pair in the session state

key string, value any

error

(MutableSession).Get

Retrieves a value for a given key

key string

value any, error

(MutableSession).All

Returns an iterator over all key-value pairs in the session

none

iterator of key-value pairs

(MutableSession).ID

Returns the session ID

none

string

(MutableSession).AppName

Returns the application name associated with the session

none

string

(MutableSession).UserID

Returns the user ID associated with the session

none

string

(MutableSession).LastUpdateTime

Returns the last update time of the session

none

time.Time

(MutableSession).Events

Returns the list of events associated with the session

none

slice of events

(MutableSession).State

Returns the underlying session state object

none

any


This documentation focuses exclusively on the testing and verification of the MutableSession functionalities, which are a core part of the session management subsystem as described in Session Management.