...
1 package session
2
3 import (
4 "github.com/gin-contrib/sessions"
5
6 "edge-infra.dev/pkg/lib/uuid"
7 )
8
9
10 type MockSessions struct {
11 name string
12 sessions map[interface{}]MockSession
13 opts sessions.Options
14 }
15
16
17 type MockSession struct {
18 id string
19 key interface{}
20 val interface{}
21 }
22
23
24 func NewMockSessions() *MockSessions {
25 return NewMockSessionsWithOptions("mock-sessions", make(map[interface{}]MockSession))
26 }
27
28
29 func NewMockSessionsWithOptions(name string, sess map[interface{}]MockSession) *MockSessions {
30 return &MockSessions{
31 name: name,
32 sessions: sess,
33 }
34 }
35
36 func (m *MockSessions) ID() string {
37 return ""
38 }
39
40
41 func (m *MockSessions) Get(key interface{}) interface{} {
42 return m.sessions[key].val
43 }
44
45
46 func (m *MockSessions) Set(key interface{}, val interface{}) {
47 m.sessions[key] = MockSession{
48 id: uuid.New().UUID,
49 key: key,
50 val: val,
51 }
52 }
53
54
55 func (m *MockSessions) Delete(key interface{}) {
56 delete(m.sessions, key)
57 }
58
59
60 func (m *MockSessions) Clear() {
61 m.sessions = make(map[interface{}]MockSession)
62 }
63
64 func (m *MockSessions) AddFlash(_ interface{}, _ ...string) {
65
66 }
67
68 func (m *MockSessions) Flashes(_ ...string) []interface{} {
69
70 return make([]interface{}, 0)
71 }
72
73
74 func (m *MockSessions) Options(opts sessions.Options) {
75 m.opts = opts
76 }
77
78
79 func (m *MockSessions) Save() error {
80 return nil
81 }
82
View as plain text