package session import ( "github.com/gin-contrib/sessions" "edge-infra.dev/pkg/lib/uuid" ) // MockSessions represents a session store in memory. type MockSessions struct { name string sessions map[interface{}]MockSession opts sessions.Options } // MockSession represents a single session. type MockSession struct { id string key interface{} val interface{} } // NewMockSessions returns a new instance of MockSessions. func NewMockSessions() *MockSessions { return NewMockSessionsWithOptions("mock-sessions", make(map[interface{}]MockSession)) } // NewMockSessionsWithOptions returns a new instance of MockSessions with the specified params. func NewMockSessionsWithOptions(name string, sess map[interface{}]MockSession) *MockSessions { return &MockSessions{ name: name, sessions: sess, } } func (m *MockSessions) ID() string { return "" } // Get returns a session whose key is specified. func (m *MockSessions) Get(key interface{}) interface{} { return m.sessions[key].val } // Set sets a session with the specified key and value. func (m *MockSessions) Set(key interface{}, val interface{}) { m.sessions[key] = MockSession{ id: uuid.New().UUID, key: key, val: val, } } // Delete deletes a session whose key is specified. func (m *MockSessions) Delete(key interface{}) { delete(m.sessions, key) } // Clear clears all sessions. func (m *MockSessions) Clear() { m.sessions = make(map[interface{}]MockSession) } func (m *MockSessions) AddFlash(_ interface{}, _ ...string) { // TODO(pa250194_ncrvoyix): decided not to implement as the proxy does not call it. } func (m *MockSessions) Flashes(_ ...string) []interface{} { // TODO(pa250194_ncrvoyix): decided not to implement as the proxy does not call it. return make([]interface{}, 0) } // Options sets the options for the sessions. func (m *MockSessions) Options(opts sessions.Options) { m.opts = opts } // Save retruns nil as set adds to map of sessions already. func (m *MockSessions) Save() error { return nil }