-
Notifications
You must be signed in to change notification settings - Fork 7
/
store_test.go
285 lines (265 loc) · 7.89 KB
/
store_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package sessionup
import (
"context"
"sync"
)
var (
lockStoreMockCreate sync.RWMutex
lockStoreMockDeleteByID sync.RWMutex
lockStoreMockDeleteByUserKey sync.RWMutex
lockStoreMockFetchByID sync.RWMutex
lockStoreMockFetchByUserKey sync.RWMutex
)
// Ensure, that StoreMock does implement Store.
// If this is not the case, regenerate this file with moq.
var _ Store = &StoreMock{}
// StoreMock is a mock implementation of Store.
//
// func TestSomethingThatUsesStore(t *testing.T) {
//
// // make and configure a mocked Store
// mockedStore := &StoreMock{
// CreateFunc: func(ctx context.Context, s Session) error {
// panic("mock out the Create method")
// },
// DeleteByIDFunc: func(ctx context.Context, id string) error {
// panic("mock out the DeleteByID method")
// },
// DeleteByUserKeyFunc: func(ctx context.Context, key string, expID ...string) error {
// panic("mock out the DeleteByUserKey method")
// },
// FetchByIDFunc: func(ctx context.Context, id string) (Session, bool, error) {
// panic("mock out the FetchByID method")
// },
// FetchByUserKeyFunc: func(ctx context.Context, key string) ([]Session, error) {
// panic("mock out the FetchByUserKey method")
// },
// }
//
// // use mockedStore in code that requires Store
// // and then make assertions.
//
// }
type StoreMock struct {
// CreateFunc mocks the Create method.
CreateFunc func(ctx context.Context, s Session) error
// DeleteByIDFunc mocks the DeleteByID method.
DeleteByIDFunc func(ctx context.Context, id string) error
// DeleteByUserKeyFunc mocks the DeleteByUserKey method.
DeleteByUserKeyFunc func(ctx context.Context, key string, expID ...string) error
// FetchByIDFunc mocks the FetchByID method.
FetchByIDFunc func(ctx context.Context, id string) (Session, bool, error)
// FetchByUserKeyFunc mocks the FetchByUserKey method.
FetchByUserKeyFunc func(ctx context.Context, key string) ([]Session, error)
// calls tracks calls to the methods.
calls struct {
// Create holds details about calls to the Create method.
Create []struct {
// Ctx is the ctx argument value.
Ctx context.Context
// S is the s argument value.
S Session
}
// DeleteByID holds details about calls to the DeleteByID method.
DeleteByID []struct {
// Ctx is the ctx argument value.
Ctx context.Context
// ID is the id argument value.
ID string
}
// DeleteByUserKey holds details about calls to the DeleteByUserKey method.
DeleteByUserKey []struct {
// Ctx is the ctx argument value.
Ctx context.Context
// Key is the key argument value.
Key string
// ExpID is the expID argument value.
ExpID []string
}
// FetchByID holds details about calls to the FetchByID method.
FetchByID []struct {
// Ctx is the ctx argument value.
Ctx context.Context
// ID is the id argument value.
ID string
}
// FetchByUserKey holds details about calls to the FetchByUserKey method.
FetchByUserKey []struct {
// Ctx is the ctx argument value.
Ctx context.Context
// Key is the key argument value.
Key string
}
}
}
// Create calls CreateFunc.
func (mock *StoreMock) Create(ctx context.Context, s Session) error {
if mock.CreateFunc == nil {
panic("StoreMock.CreateFunc: method is nil but Store.Create was just called")
}
callInfo := struct {
Ctx context.Context
S Session
}{
Ctx: ctx,
S: s,
}
lockStoreMockCreate.Lock()
mock.calls.Create = append(mock.calls.Create, callInfo)
lockStoreMockCreate.Unlock()
return mock.CreateFunc(ctx, s)
}
// CreateCalls gets all the calls that were made to Create.
// Check the length with:
// len(mockedStore.CreateCalls())
func (mock *StoreMock) CreateCalls() []struct {
Ctx context.Context
S Session
} {
var calls []struct {
Ctx context.Context
S Session
}
lockStoreMockCreate.RLock()
calls = mock.calls.Create
lockStoreMockCreate.RUnlock()
return calls
}
// DeleteByID calls DeleteByIDFunc.
func (mock *StoreMock) DeleteByID(ctx context.Context, id string) error {
if mock.DeleteByIDFunc == nil {
panic("StoreMock.DeleteByIDFunc: method is nil but Store.DeleteByID was just called")
}
callInfo := struct {
Ctx context.Context
ID string
}{
Ctx: ctx,
ID: id,
}
lockStoreMockDeleteByID.Lock()
mock.calls.DeleteByID = append(mock.calls.DeleteByID, callInfo)
lockStoreMockDeleteByID.Unlock()
return mock.DeleteByIDFunc(ctx, id)
}
// DeleteByIDCalls gets all the calls that were made to DeleteByID.
// Check the length with:
// len(mockedStore.DeleteByIDCalls())
func (mock *StoreMock) DeleteByIDCalls() []struct {
Ctx context.Context
ID string
} {
var calls []struct {
Ctx context.Context
ID string
}
lockStoreMockDeleteByID.RLock()
calls = mock.calls.DeleteByID
lockStoreMockDeleteByID.RUnlock()
return calls
}
// DeleteByUserKey calls DeleteByUserKeyFunc.
func (mock *StoreMock) DeleteByUserKey(ctx context.Context, key string, expID ...string) error {
if mock.DeleteByUserKeyFunc == nil {
panic("StoreMock.DeleteByUserKeyFunc: method is nil but Store.DeleteByUserKey was just called")
}
callInfo := struct {
Ctx context.Context
Key string
ExpID []string
}{
Ctx: ctx,
Key: key,
ExpID: expID,
}
lockStoreMockDeleteByUserKey.Lock()
mock.calls.DeleteByUserKey = append(mock.calls.DeleteByUserKey, callInfo)
lockStoreMockDeleteByUserKey.Unlock()
return mock.DeleteByUserKeyFunc(ctx, key, expID...)
}
// DeleteByUserKeyCalls gets all the calls that were made to DeleteByUserKey.
// Check the length with:
// len(mockedStore.DeleteByUserKeyCalls())
func (mock *StoreMock) DeleteByUserKeyCalls() []struct {
Ctx context.Context
Key string
ExpID []string
} {
var calls []struct {
Ctx context.Context
Key string
ExpID []string
}
lockStoreMockDeleteByUserKey.RLock()
calls = mock.calls.DeleteByUserKey
lockStoreMockDeleteByUserKey.RUnlock()
return calls
}
// FetchByID calls FetchByIDFunc.
func (mock *StoreMock) FetchByID(ctx context.Context, id string) (Session, bool, error) {
if mock.FetchByIDFunc == nil {
panic("StoreMock.FetchByIDFunc: method is nil but Store.FetchByID was just called")
}
callInfo := struct {
Ctx context.Context
ID string
}{
Ctx: ctx,
ID: id,
}
lockStoreMockFetchByID.Lock()
mock.calls.FetchByID = append(mock.calls.FetchByID, callInfo)
lockStoreMockFetchByID.Unlock()
return mock.FetchByIDFunc(ctx, id)
}
// FetchByIDCalls gets all the calls that were made to FetchByID.
// Check the length with:
// len(mockedStore.FetchByIDCalls())
func (mock *StoreMock) FetchByIDCalls() []struct {
Ctx context.Context
ID string
} {
var calls []struct {
Ctx context.Context
ID string
}
lockStoreMockFetchByID.RLock()
calls = mock.calls.FetchByID
lockStoreMockFetchByID.RUnlock()
return calls
}
// FetchByUserKey calls FetchByUserKeyFunc.
func (mock *StoreMock) FetchByUserKey(ctx context.Context, key string) ([]Session, error) {
if mock.FetchByUserKeyFunc == nil {
panic("StoreMock.FetchByUserKeyFunc: method is nil but Store.FetchByUserKey was just called")
}
callInfo := struct {
Ctx context.Context
Key string
}{
Ctx: ctx,
Key: key,
}
lockStoreMockFetchByUserKey.Lock()
mock.calls.FetchByUserKey = append(mock.calls.FetchByUserKey, callInfo)
lockStoreMockFetchByUserKey.Unlock()
return mock.FetchByUserKeyFunc(ctx, key)
}
// FetchByUserKeyCalls gets all the calls that were made to FetchByUserKey.
// Check the length with:
// len(mockedStore.FetchByUserKeyCalls())
func (mock *StoreMock) FetchByUserKeyCalls() []struct {
Ctx context.Context
Key string
} {
var calls []struct {
Ctx context.Context
Key string
}
lockStoreMockFetchByUserKey.RLock()
calls = mock.calls.FetchByUserKey
lockStoreMockFetchByUserKey.RUnlock()
return calls
}