@@ -91,32 +91,35 @@ func TestSessionsStoreMigration(t *testing.T) {
91
91
populateDB func (
92
92
t * testing.T , kvStore * BoltStore ,
93
93
accountStore accounts.Store ,
94
- )
94
+ ) [] * Session
95
95
}{
96
96
{
97
97
name : "empty" ,
98
98
populateDB : func (t * testing.T , store * BoltStore ,
99
- _ accounts.Store ) {
99
+ _ accounts.Store ) [] * Session {
100
100
101
101
// Don't populate the DB.
102
+ return []* Session {}
102
103
},
103
104
},
104
105
{
105
106
name : "one session no options" ,
106
107
populateDB : func (t * testing.T , store * BoltStore ,
107
- _ accounts.Store ) {
108
+ _ accounts.Store ) [] * Session {
108
109
109
110
_ , err := store .NewSession (
110
111
ctx , "test" , TypeMacaroonAdmin ,
111
112
time .Unix (1000 , 0 ), "" ,
112
113
)
113
114
require .NoError (t , err )
115
+
116
+ return getBoltStoreSessions (t , store )
114
117
},
115
118
},
116
119
{
117
120
name : "multiple sessions no options" ,
118
121
populateDB : func (t * testing.T , store * BoltStore ,
119
- _ accounts.Store ) {
122
+ _ accounts.Store ) [] * Session {
120
123
121
124
_ , err := store .NewSession (
122
125
ctx , "session1" , TypeMacaroonAdmin ,
@@ -135,25 +138,29 @@ func TestSessionsStoreMigration(t *testing.T) {
135
138
time .Unix (1000 , 0 ), "" ,
136
139
)
137
140
require .NoError (t , err )
141
+
142
+ return getBoltStoreSessions (t , store )
138
143
},
139
144
},
140
145
{
141
146
name : "one session with one privacy flag" ,
142
147
populateDB : func (t * testing.T , store * BoltStore ,
143
- _ accounts.Store ) {
148
+ _ accounts.Store ) [] * Session {
144
149
145
150
_ , err := store .NewSession (
146
151
ctx , "test" , TypeMacaroonAdmin ,
147
152
time .Unix (1000 , 0 ), "" ,
148
153
WithPrivacy (PrivacyFlags {ClearPubkeys }),
149
154
)
150
155
require .NoError (t , err )
156
+
157
+ return getBoltStoreSessions (t , store )
151
158
},
152
159
},
153
160
{
154
161
name : "one session with multiple privacy flags" ,
155
162
populateDB : func (t * testing.T , store * BoltStore ,
156
- _ accounts.Store ) {
163
+ _ accounts.Store ) [] * Session {
157
164
158
165
_ , err := store .NewSession (
159
166
ctx , "test" , TypeMacaroonAdmin ,
@@ -164,12 +171,14 @@ func TestSessionsStoreMigration(t *testing.T) {
164
171
}),
165
172
)
166
173
require .NoError (t , err )
174
+
175
+ return getBoltStoreSessions (t , store )
167
176
},
168
177
},
169
178
{
170
179
name : "one session with a feature config" ,
171
180
populateDB : func (t * testing.T , store * BoltStore ,
172
- _ accounts.Store ) {
181
+ _ accounts.Store ) [] * Session {
173
182
174
183
featureConfig := map [string ][]byte {
175
184
"AutoFees" : {1 , 2 , 3 , 4 },
@@ -182,25 +191,29 @@ func TestSessionsStoreMigration(t *testing.T) {
182
191
WithFeatureConfig (featureConfig ),
183
192
)
184
193
require .NoError (t , err )
194
+
195
+ return getBoltStoreSessions (t , store )
185
196
},
186
197
},
187
198
{
188
199
name : "one session with dev server" ,
189
200
populateDB : func (t * testing.T , store * BoltStore ,
190
- _ accounts.Store ) {
201
+ _ accounts.Store ) [] * Session {
191
202
192
203
_ , err := store .NewSession (
193
204
ctx , "test" , TypeMacaroonAdmin ,
194
205
time .Unix (1000 , 0 ), "" ,
195
206
WithDevServer (),
196
207
)
197
208
require .NoError (t , err )
209
+
210
+ return getBoltStoreSessions (t , store )
198
211
},
199
212
},
200
213
{
201
214
name : "one session with macaroon recipe" ,
202
215
populateDB : func (t * testing.T , store * BoltStore ,
203
- _ accounts.Store ) {
216
+ _ accounts.Store ) [] * Session {
204
217
205
218
// this test uses caveats & perms from the
206
219
// tlv_test.go
@@ -210,12 +223,14 @@ func TestSessionsStoreMigration(t *testing.T) {
210
223
WithMacaroonRecipe (caveats , perms ),
211
224
)
212
225
require .NoError (t , err )
226
+
227
+ return getBoltStoreSessions (t , store )
213
228
},
214
229
},
215
230
{
216
231
name : "one session with macaroon recipe nil caveats" ,
217
232
populateDB : func (t * testing.T , store * BoltStore ,
218
- _ accounts.Store ) {
233
+ _ accounts.Store ) [] * Session {
219
234
220
235
// this test uses perms from the tlv_test.go
221
236
_ , err := store .NewSession (
@@ -224,12 +239,14 @@ func TestSessionsStoreMigration(t *testing.T) {
224
239
WithMacaroonRecipe (nil , perms ),
225
240
)
226
241
require .NoError (t , err )
242
+
243
+ return getBoltStoreSessions (t , store )
227
244
},
228
245
},
229
246
{
230
247
name : "one session with macaroon recipe nil perms" ,
231
248
populateDB : func (t * testing.T , store * BoltStore ,
232
- _ accounts.Store ) {
249
+ _ accounts.Store ) [] * Session {
233
250
234
251
// this test uses caveats from the tlv_test.go
235
252
_ , err := store .NewSession (
@@ -238,25 +255,29 @@ func TestSessionsStoreMigration(t *testing.T) {
238
255
WithMacaroonRecipe (caveats , nil ),
239
256
)
240
257
require .NoError (t , err )
258
+
259
+ return getBoltStoreSessions (t , store )
241
260
},
242
261
},
243
262
{
244
263
name : "macaroon recipe with nil perms and caveats" ,
245
264
populateDB : func (t * testing.T , store * BoltStore ,
246
- _ accounts.Store ) {
265
+ _ accounts.Store ) [] * Session {
247
266
248
267
_ , err := store .NewSession (
249
268
ctx , "test" , TypeMacaroonAdmin ,
250
269
time .Unix (1000 , 0 ), "foo.bar.baz:1234" ,
251
270
WithMacaroonRecipe (nil , nil ),
252
271
)
253
272
require .NoError (t , err )
273
+
274
+ return getBoltStoreSessions (t , store )
254
275
},
255
276
},
256
277
{
257
278
name : "one session with a linked account" ,
258
279
populateDB : func (t * testing.T , store * BoltStore ,
259
- acctStore accounts.Store ) {
280
+ acctStore accounts.Store ) [] * Session {
260
281
261
282
// Create an account with balance
262
283
acct , err := acctStore .NewAccount (
@@ -289,12 +310,14 @@ func TestSessionsStoreMigration(t *testing.T) {
289
310
WithMacaroonRecipe (sessCaveats , nil ),
290
311
)
291
312
require .NoError (t , err )
313
+
314
+ return getBoltStoreSessions (t , store )
292
315
},
293
316
},
294
317
{
295
318
name : "linked session" ,
296
319
populateDB : func (t * testing.T , store * BoltStore ,
297
- _ accounts.Store ) {
320
+ _ accounts.Store ) [] * Session {
298
321
299
322
// First create the initial session for the
300
323
// group.
@@ -325,6 +348,8 @@ func TestSessionsStoreMigration(t *testing.T) {
325
348
WithLinkedGroupID (& sess1 .ID ),
326
349
)
327
350
require .NoError (t , err )
351
+
352
+ return getBoltStoreSessions (t , store )
328
353
},
329
354
},
330
355
{
@@ -355,15 +380,7 @@ func TestSessionsStoreMigration(t *testing.T) {
355
380
356
381
// populate the kvStore with the test data, in
357
382
// preparation for the test.
358
- test .populateDB (t , kvStore , accountStore )
359
-
360
- // Before we migrate the sessions, we fetch all sessions
361
- // from the kv store, to ensure that the migration
362
- // function doesn't mutate the bbolt store sessions.
363
- // We can then compare them to the sql sessions after
364
- // the migration has been executed.
365
- kvSessions , err := kvStore .ListAllSessions (ctx )
366
- require .NoError (t , err )
383
+ kvSessions := test .populateDB (t , kvStore , accountStore )
367
384
368
385
// Proceed to create the sql store and execute the
369
386
// migration.
@@ -392,7 +409,7 @@ func TestSessionsStoreMigration(t *testing.T) {
392
409
// them will contain up to 10 linked sessions. The rest of the session will have
393
410
// the rest of the session options randomized.
394
411
func randomizedSessions (t * testing.T , kvStore * BoltStore ,
395
- accountsStore accounts.Store ) {
412
+ accountsStore accounts.Store ) [] * Session {
396
413
397
414
ctx := context .Background ()
398
415
@@ -547,6 +564,8 @@ func randomizedSessions(t *testing.T, kvStore *BoltStore,
547
564
err = shiftStateUnsafe (kvStore , activeSess .ID , lastState (i ))
548
565
require .NoError (t , err )
549
566
}
567
+
568
+ return getBoltStoreSessions (t , kvStore )
550
569
}
551
570
552
571
// macaroonType returns a macaroon type based on the given index by taking the
@@ -741,6 +760,16 @@ func randomString(n int) string {
741
760
return string (b )
742
761
}
743
762
763
+ // getBoltStoreSessions is a helper function that fetches all sessions
764
+ // from the kv store, while already asserting that there no error occurs
765
+ // when retrieving the sessions.
766
+ func getBoltStoreSessions (t * testing.T , db * BoltStore ) []* Session {
767
+ kvSessions , err := getBBoltSessions (db .DB )
768
+ require .NoError (t , err )
769
+
770
+ return kvSessions
771
+ }
772
+
744
773
// shiftStateUnsafe updates the state of the session with the given ID to the
745
774
// "dest" state, without checking if the state transition is legal.
746
775
//
0 commit comments