34
34
testEntryValue = []byte {1 , 2 , 3 }
35
35
)
36
36
37
+ // expectedResult represents the expected result of a migration test.
38
+ type expectedResult struct {
39
+ kvEntries []* kvEntry
40
+ }
41
+
37
42
// TestFirewallDBMigration tests the migration of firewalldb from a bolt
38
43
// backend to a SQL database. Note that this test does not attempt to be a
39
44
// complete migration test.
@@ -72,10 +77,10 @@ func TestFirewallDBMigration(t *testing.T) {
72
77
return store , genericExecutor
73
78
}
74
79
75
- // The assertMigrationResults function will currently assert that
80
+ // The assertKvStoreMigrationResults function will currently assert that
76
81
// the migrated kv stores entries in the SQLDB match the original kv
77
82
// stores entries in the BoltDB.
78
- assertMigrationResults := func (t * testing.T , sqlStore * SQLDB ,
83
+ assertKvStoreMigrationResults := func (t * testing.T , sqlStore * SQLDB ,
79
84
kvEntries []* kvEntry ) {
80
85
81
86
var (
@@ -213,6 +218,17 @@ func TestFirewallDBMigration(t *testing.T) {
213
218
}
214
219
}
215
220
221
+ // The assertMigrationResults function will currently assert that
222
+ // the migrated kv stores records in the SQLDB match the original kv
223
+ // stores records in the BoltDB.
224
+ assertMigrationResults := func (t * testing.T , sqlStore * SQLDB ,
225
+ expRes * expectedResult ) {
226
+
227
+ // Assert that the kv store migration results match the expected
228
+ // results.
229
+ assertKvStoreMigrationResults (t , sqlStore , expRes .kvEntries )
230
+ }
231
+
216
232
// The tests slice contains all the tests that we will run for the
217
233
// migration of the firewalldb from a BoltDB to a SQLDB.
218
234
// Note that the tests currently only test the migration of the KV
@@ -221,16 +237,20 @@ func TestFirewallDBMigration(t *testing.T) {
221
237
tests := []struct {
222
238
name string
223
239
populateDB func (t * testing.T , ctx context.Context ,
224
- boltDB * BoltDB , sessionStore session.Store ) [] * kvEntry
240
+ boltDB * BoltDB , sessionStore session.Store ) * expectedResult
225
241
}{
226
242
{
227
243
name : "empty" ,
228
244
populateDB : func (t * testing.T , ctx context.Context ,
229
245
boltDB * BoltDB ,
230
- sessionStore session.Store ) []* kvEntry {
246
+ sessionStore session.Store ) * expectedResult {
247
+
248
+ // Don't populate the DB, and return empty kv
249
+ // records and privacy pairs.
231
250
232
- // Don't populate the DB.
233
- return make ([]* kvEntry , 0 )
251
+ return & expectedResult {
252
+ kvEntries : []* kvEntry {},
253
+ }
234
254
},
235
255
},
236
256
{
@@ -314,7 +334,7 @@ func TestFirewallDBMigration(t *testing.T) {
314
334
// globalEntries populates the kv store with one global entry for the temp
315
335
// store, and one for the perm store.
316
336
func globalEntries (t * testing.T , ctx context.Context , boltDB * BoltDB ,
317
- _ session.Store ) [] * kvEntry {
337
+ _ session.Store ) * expectedResult {
318
338
319
339
return insertTempAndPermEntry (
320
340
t , ctx , boltDB , testRuleName , fn .None [[]byte ](),
@@ -326,7 +346,7 @@ func globalEntries(t *testing.T, ctx context.Context, boltDB *BoltDB,
326
346
// entry for the local temp store, and one session specific entry for the perm
327
347
// local store.
328
348
func sessionSpecificEntries (t * testing.T , ctx context.Context , boltDB * BoltDB ,
329
- sessionStore session.Store ) [] * kvEntry {
349
+ sessionStore session.Store ) * expectedResult {
330
350
331
351
groupAlias := getNewSessionAlias (t , ctx , sessionStore )
332
352
@@ -340,7 +360,7 @@ func sessionSpecificEntries(t *testing.T, ctx context.Context, boltDB *BoltDB,
340
360
// entry for the local temp store, and one feature specific entry for the perm
341
361
// local store.
342
362
func featureSpecificEntries (t * testing.T , ctx context.Context , boltDB * BoltDB ,
343
- sessionStore session.Store ) [] * kvEntry {
363
+ sessionStore session.Store ) * expectedResult {
344
364
345
365
groupAlias := getNewSessionAlias (t , ctx , sessionStore )
346
366
@@ -358,11 +378,11 @@ func featureSpecificEntries(t *testing.T, ctx context.Context, boltDB *BoltDB,
358
378
// any entries when the entry set is more complex than just a single entry at
359
379
// each level.
360
380
func allEntryCombinations (t * testing.T , ctx context.Context , boltDB * BoltDB ,
361
- sessionStore session.Store ) [] * kvEntry {
381
+ sessionStore session.Store ) * expectedResult {
362
382
363
383
var result []* kvEntry
364
- add := func (entry [] * kvEntry ) {
365
- result = append (result , entry ... )
384
+ add := func (entry * expectedResult ) {
385
+ result = append (result , entry .kvEntries . .. )
366
386
}
367
387
368
388
// First lets create standard entries at all levels, which represents
@@ -446,7 +466,9 @@ func allEntryCombinations(t *testing.T, ctx context.Context, boltDB *BoltDB,
446
466
fn .Some (testFeatureName ), testEntryKey4 , emptyValue ,
447
467
))
448
468
449
- return result
469
+ return & expectedResult {
470
+ kvEntries : result ,
471
+ }
450
472
}
451
473
452
474
func getNewSessionAlias (t * testing.T , ctx context.Context ,
@@ -467,7 +489,7 @@ func getNewSessionAlias(t *testing.T, ctx context.Context,
467
489
func insertTempAndPermEntry (t * testing.T , ctx context.Context ,
468
490
boltDB * BoltDB , ruleName string , groupAlias fn.Option [[]byte ],
469
491
featureNameOpt fn.Option [string ], entryKey string ,
470
- entryValue []byte ) [] * kvEntry {
492
+ entryValue []byte ) * expectedResult {
471
493
472
494
tempKvEntry := & kvEntry {
473
495
ruleName : ruleName ,
@@ -491,7 +513,9 @@ func insertTempAndPermEntry(t *testing.T, ctx context.Context,
491
513
492
514
insertKvEntry (t , ctx , boltDB , permKvEntry )
493
515
494
- return []* kvEntry {tempKvEntry , permKvEntry }
516
+ return & expectedResult {
517
+ kvEntries : []* kvEntry {tempKvEntry , permKvEntry },
518
+ }
495
519
}
496
520
497
521
// insertKvEntry populates the kv store with passed entry, and asserts that the
@@ -540,7 +564,7 @@ func insertKvEntry(t *testing.T, ctx context.Context,
540
564
// across all possible combinations of different levels of entries in the kv
541
565
// store. All values and different bucket names are randomly generated.
542
566
func randomKVEntries (t * testing.T , ctx context.Context ,
543
- boltDB * BoltDB , sessionStore session.Store ) [] * kvEntry {
567
+ boltDB * BoltDB , sessionStore session.Store ) * expectedResult {
544
568
545
569
var (
546
570
// We set the number of entries to insert to 1000, as that
@@ -651,7 +675,9 @@ func randomKVEntries(t *testing.T, ctx context.Context,
651
675
insertedEntries = append (insertedEntries , entry )
652
676
}
653
677
654
- return insertedEntries
678
+ return & expectedResult {
679
+ kvEntries : insertedEntries ,
680
+ }
655
681
}
656
682
657
683
// randomString generates a random string of the passed length n.
0 commit comments