3434 testEntryValue = []byte {1 , 2 , 3 }
3535)
3636
37+ // expectedResult represents the expected result of a migration test.
38+ type expectedResult struct {
39+ kvEntries []* kvEntry
40+ }
41+
3742// TestFirewallDBMigration tests the migration of firewalldb from a bolt
3843// backend to a SQL database. Note that this test does not attempt to be a
3944// complete migration test.
@@ -72,10 +77,10 @@ func TestFirewallDBMigration(t *testing.T) {
7277 return store , genericExecutor
7378 }
7479
75- // The assertMigrationResults function will currently assert that
80+ // The assertKvStoreMigrationResults function will currently assert that
7681 // the migrated kv stores entries in the SQLDB match the original kv
7782 // stores entries in the BoltDB.
78- assertMigrationResults := func (t * testing.T , sqlStore * SQLDB ,
83+ assertKvStoreMigrationResults := func (t * testing.T , sqlStore * SQLDB ,
7984 kvEntries []* kvEntry ) {
8085
8186 var (
@@ -213,6 +218,17 @@ func TestFirewallDBMigration(t *testing.T) {
213218 }
214219 }
215220
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+
216232 // The tests slice contains all the tests that we will run for the
217233 // migration of the firewalldb from a BoltDB to a SQLDB.
218234 // Note that the tests currently only test the migration of the KV
@@ -221,16 +237,20 @@ func TestFirewallDBMigration(t *testing.T) {
221237 tests := []struct {
222238 name string
223239 populateDB func (t * testing.T , ctx context.Context ,
224- boltDB * BoltDB , sessionStore session.Store ) [] * kvEntry
240+ boltDB * BoltDB , sessionStore session.Store ) * expectedResult
225241 }{
226242 {
227243 name : "empty" ,
228244 populateDB : func (t * testing.T , ctx context.Context ,
229245 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.
231250
232- // Don't populate the DB.
233- return make ([]* kvEntry , 0 )
251+ return & expectedResult {
252+ kvEntries : []* kvEntry {},
253+ }
234254 },
235255 },
236256 {
@@ -314,7 +334,7 @@ func TestFirewallDBMigration(t *testing.T) {
314334// globalEntries populates the kv store with one global entry for the temp
315335// store, and one for the perm store.
316336func globalEntries (t * testing.T , ctx context.Context , boltDB * BoltDB ,
317- _ session.Store ) [] * kvEntry {
337+ _ session.Store ) * expectedResult {
318338
319339 return insertTempAndPermEntry (
320340 t , ctx , boltDB , testRuleName , fn .None [[]byte ](),
@@ -326,7 +346,7 @@ func globalEntries(t *testing.T, ctx context.Context, boltDB *BoltDB,
326346// entry for the local temp store, and one session specific entry for the perm
327347// local store.
328348func sessionSpecificEntries (t * testing.T , ctx context.Context , boltDB * BoltDB ,
329- sessionStore session.Store ) [] * kvEntry {
349+ sessionStore session.Store ) * expectedResult {
330350
331351 groupAlias := getNewSessionAlias (t , ctx , sessionStore )
332352
@@ -340,7 +360,7 @@ func sessionSpecificEntries(t *testing.T, ctx context.Context, boltDB *BoltDB,
340360// entry for the local temp store, and one feature specific entry for the perm
341361// local store.
342362func featureSpecificEntries (t * testing.T , ctx context.Context , boltDB * BoltDB ,
343- sessionStore session.Store ) [] * kvEntry {
363+ sessionStore session.Store ) * expectedResult {
344364
345365 groupAlias := getNewSessionAlias (t , ctx , sessionStore )
346366
@@ -358,11 +378,11 @@ func featureSpecificEntries(t *testing.T, ctx context.Context, boltDB *BoltDB,
358378// any entries when the entry set is more complex than just a single entry at
359379// each level.
360380func allEntryCombinations (t * testing.T , ctx context.Context , boltDB * BoltDB ,
361- sessionStore session.Store ) [] * kvEntry {
381+ sessionStore session.Store ) * expectedResult {
362382
363383 var result []* kvEntry
364- add := func (entry [] * kvEntry ) {
365- result = append (result , entry ... )
384+ add := func (entry * expectedResult ) {
385+ result = append (result , entry .kvEntries . .. )
366386 }
367387
368388 // First lets create standard entries at all levels, which represents
@@ -446,7 +466,9 @@ func allEntryCombinations(t *testing.T, ctx context.Context, boltDB *BoltDB,
446466 fn .Some (testFeatureName ), testEntryKey4 , emptyValue ,
447467 ))
448468
449- return result
469+ return & expectedResult {
470+ kvEntries : result ,
471+ }
450472}
451473
452474func getNewSessionAlias (t * testing.T , ctx context.Context ,
@@ -467,7 +489,7 @@ func getNewSessionAlias(t *testing.T, ctx context.Context,
467489func insertTempAndPermEntry (t * testing.T , ctx context.Context ,
468490 boltDB * BoltDB , ruleName string , groupAlias fn.Option [[]byte ],
469491 featureNameOpt fn.Option [string ], entryKey string ,
470- entryValue []byte ) [] * kvEntry {
492+ entryValue []byte ) * expectedResult {
471493
472494 tempKvEntry := & kvEntry {
473495 ruleName : ruleName ,
@@ -491,7 +513,9 @@ func insertTempAndPermEntry(t *testing.T, ctx context.Context,
491513
492514 insertKvEntry (t , ctx , boltDB , permKvEntry )
493515
494- return []* kvEntry {tempKvEntry , permKvEntry }
516+ return & expectedResult {
517+ kvEntries : []* kvEntry {tempKvEntry , permKvEntry },
518+ }
495519}
496520
497521// insertKvEntry populates the kv store with passed entry, and asserts that the
@@ -540,7 +564,7 @@ func insertKvEntry(t *testing.T, ctx context.Context,
540564// across all possible combinations of different levels of entries in the kv
541565// store. All values and different bucket names are randomly generated.
542566func randomKVEntries (t * testing.T , ctx context.Context ,
543- boltDB * BoltDB , sessionStore session.Store ) [] * kvEntry {
567+ boltDB * BoltDB , sessionStore session.Store ) * expectedResult {
544568
545569 var (
546570 // We set the number of entries to insert to 1000, as that
@@ -651,7 +675,9 @@ func randomKVEntries(t *testing.T, ctx context.Context,
651675 insertedEntries = append (insertedEntries , entry )
652676 }
653677
654- return insertedEntries
678+ return & expectedResult {
679+ kvEntries : insertedEntries ,
680+ }
655681}
656682
657683// randomString generates a random string of the passed length n.
0 commit comments