3434 testEntryValue = []byte {1 , 2 , 3 }
3535)
3636
37+ // expectedResult represents the expected result of a migration test.
38+ type expectedResult struct {
39+ kvEntries fn.Option [[]* 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,20 @@ 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+ // If the expected result contains kv records, then we
228+ // assert that the kv store migration results match
229+ // the expected results.
230+ expRes .kvEntries .WhenSome (func (kvEntries []* kvEntry ) {
231+ assertKvStoreMigrationResults (t , sqlStore , kvEntries )
232+ })
233+ }
234+
216235 // The tests slice contains all the tests that we will run for the
217236 // migration of the firewalldb from a BoltDB to a SQLDB.
218237 // Note that the tests currently only test the migration of the KV
@@ -221,16 +240,22 @@ func TestFirewallDBMigration(t *testing.T) {
221240 tests := []struct {
222241 name string
223242 populateDB func (t * testing.T , ctx context.Context ,
224- boltDB * BoltDB , sessionStore session.Store ) [] * kvEntry
243+ boltDB * BoltDB , sessionStore session.Store ) * expectedResult
225244 }{
226245 {
227246 name : "empty" ,
228247 populateDB : func (t * testing.T , ctx context.Context ,
229248 boltDB * BoltDB ,
230- sessionStore session.Store ) []* kvEntry {
249+ sessionStore session.Store ) * expectedResult {
250+
251+ // Don't populate the DB, and return empty kv
252+ // records and privacy pairs.
231253
232- // Don't populate the DB.
233- return make ([]* kvEntry , 0 )
254+ return & expectedResult {
255+ kvEntries : fn .Some (
256+ []* kvEntry {},
257+ ),
258+ }
234259 },
235260 },
236261 {
@@ -314,7 +339,7 @@ func TestFirewallDBMigration(t *testing.T) {
314339// globalEntries populates the kv store with one global entry for the temp
315340// store, and one for the perm store.
316341func globalEntries (t * testing.T , ctx context.Context , boltDB * BoltDB ,
317- _ session.Store ) [] * kvEntry {
342+ _ session.Store ) * expectedResult {
318343
319344 return insertTempAndPermEntry (
320345 t , ctx , boltDB , testRuleName , fn .None [[]byte ](),
@@ -326,7 +351,7 @@ func globalEntries(t *testing.T, ctx context.Context, boltDB *BoltDB,
326351// entry for the local temp store, and one session specific entry for the perm
327352// local store.
328353func sessionSpecificEntries (t * testing.T , ctx context.Context , boltDB * BoltDB ,
329- sessionStore session.Store ) [] * kvEntry {
354+ sessionStore session.Store ) * expectedResult {
330355
331356 groupAlias := getNewSessionAlias (t , ctx , sessionStore )
332357
@@ -340,7 +365,7 @@ func sessionSpecificEntries(t *testing.T, ctx context.Context, boltDB *BoltDB,
340365// entry for the local temp store, and one feature specific entry for the perm
341366// local store.
342367func featureSpecificEntries (t * testing.T , ctx context.Context , boltDB * BoltDB ,
343- sessionStore session.Store ) [] * kvEntry {
368+ sessionStore session.Store ) * expectedResult {
344369
345370 groupAlias := getNewSessionAlias (t , ctx , sessionStore )
346371
@@ -358,11 +383,11 @@ func featureSpecificEntries(t *testing.T, ctx context.Context, boltDB *BoltDB,
358383// any entries when the entry set is more complex than just a single entry at
359384// each level.
360385func allEntryCombinations (t * testing.T , ctx context.Context , boltDB * BoltDB ,
361- sessionStore session.Store ) [] * kvEntry {
386+ sessionStore session.Store ) * expectedResult {
362387
363388 var result []* kvEntry
364- add := func (entry [] * kvEntry ) {
365- result = append (result , entry ... )
389+ add := func (entry * expectedResult ) {
390+ result = append (result , entry .kvEntries . UnwrapOrFail ( t ) . .. )
366391 }
367392
368393 // First lets create standard entries at all levels, which represents
@@ -446,7 +471,9 @@ func allEntryCombinations(t *testing.T, ctx context.Context, boltDB *BoltDB,
446471 fn .Some (testFeatureName ), testEntryKey4 , emptyValue ,
447472 ))
448473
449- return result
474+ return & expectedResult {
475+ kvEntries : fn .Some (result ),
476+ }
450477}
451478
452479func getNewSessionAlias (t * testing.T , ctx context.Context ,
@@ -467,7 +494,7 @@ func getNewSessionAlias(t *testing.T, ctx context.Context,
467494func insertTempAndPermEntry (t * testing.T , ctx context.Context ,
468495 boltDB * BoltDB , ruleName string , groupAlias fn.Option [[]byte ],
469496 featureNameOpt fn.Option [string ], entryKey string ,
470- entryValue []byte ) [] * kvEntry {
497+ entryValue []byte ) * expectedResult {
471498
472499 tempKvEntry := & kvEntry {
473500 ruleName : ruleName ,
@@ -491,7 +518,9 @@ func insertTempAndPermEntry(t *testing.T, ctx context.Context,
491518
492519 insertKvEntry (t , ctx , boltDB , permKvEntry )
493520
494- return []* kvEntry {tempKvEntry , permKvEntry }
521+ return & expectedResult {
522+ kvEntries : fn .Some ([]* kvEntry {tempKvEntry , permKvEntry }),
523+ }
495524}
496525
497526// insertKvEntry populates the kv store with passed entry, and asserts that the
@@ -540,7 +569,7 @@ func insertKvEntry(t *testing.T, ctx context.Context,
540569// across all possible combinations of different levels of entries in the kv
541570// store. All values and different bucket names are randomly generated.
542571func randomKVEntries (t * testing.T , ctx context.Context ,
543- boltDB * BoltDB , sessionStore session.Store ) [] * kvEntry {
572+ boltDB * BoltDB , sessionStore session.Store ) * expectedResult {
544573
545574 var (
546575 // We set the number of entries to insert to 1000, as that
@@ -651,7 +680,9 @@ func randomKVEntries(t *testing.T, ctx context.Context,
651680 insertedEntries = append (insertedEntries , entry )
652681 }
653682
654- return insertedEntries
683+ return & expectedResult {
684+ kvEntries : fn .Some (insertedEntries ),
685+ }
655686}
656687
657688// randomString generates a random string of the passed length n.
0 commit comments