state

package
v0.9.289 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package state provides session-scoped state management for stateful scenario testing. It enables CREATE → READ → DELETE and other ordered workflow scenarios by tracking the current state of each session identified by X-Session-ID.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InMemoryStateStore

type InMemoryStateStore struct {
	// contains filtered or unexported fields
}

InMemoryStateStore is a goroutine-safe in-process implementation of StateStore. It holds all session state in memory; state is lost on process restart.

func NewInMemoryStateStore

func NewInMemoryStateStore() *InMemoryStateStore

NewInMemoryStateStore returns a ready-to-use InMemoryStateStore.

func (*InMemoryStateStore) CurrentState

func (s *InMemoryStateStore) CurrentState(sessionID string) string

CurrentState implements StateStore.

func (*InMemoryStateStore) Get

func (s *InMemoryStateStore) Get(sessionID, key string) (any, bool)

Get implements StateStore.

func (*InMemoryStateStore) Reset

func (s *InMemoryStateStore) Reset(sessionID string)

Reset implements StateStore.

func (*InMemoryStateStore) Set

func (s *InMemoryStateStore) Set(sessionID, key string, val any)

Set implements StateStore.

func (*InMemoryStateStore) Transition

func (s *InMemoryStateStore) Transition(sessionID, fromState, toState string) error

Transition implements StateStore. If the session has no recorded state (empty string) it is treated as matching any fromState, so the first transition always succeeds.

type StateStore

type StateStore interface {
	// CurrentState returns the current state for the given session.
	// Returns "" if the session is unknown (treated as initial state).
	CurrentState(sessionID string) string

	// Transition moves a session from one state to another.
	// Returns an error if the session is not in fromState.
	Transition(sessionID, fromState, toState string) error

	// Set stores an arbitrary value under key for the session.
	Set(sessionID, key string, val any)

	// Get retrieves a value stored under key for the session.
	Get(sessionID, key string) (any, bool)

	// Reset clears all state for a session (useful for test teardown).
	Reset(sessionID string)
}

StateStore manages session state and key-value data for stateful scenario testing.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL