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		{
@@ -315,7 +340,7 @@ func TestFirewallDBMigration(t *testing.T) {
315340// globalEntries populates the kv store with one global entry for the temp 
316341// store, and one for the perm store. 
317342func  globalEntries (t  * testing.T , ctx  context.Context , boltDB  * BoltDB ,
318- 	_  session.Store ) [] * kvEntry  {
343+ 	_  session.Store ) * expectedResult  {
319344
320345	return  insertTempAndPermEntry (
321346		t , ctx , boltDB , testRuleName , fn .None [[]byte ](),
@@ -327,7 +352,7 @@ func globalEntries(t *testing.T, ctx context.Context, boltDB *BoltDB,
327352// entry for the local temp store, and one session specific entry for the perm 
328353// local store. 
329354func  sessionSpecificEntries (t  * testing.T , ctx  context.Context , boltDB  * BoltDB ,
330- 	sessionStore  session.Store ) [] * kvEntry  {
355+ 	sessionStore  session.Store ) * expectedResult  {
331356
332357	groupAlias  :=  getNewSessionAlias (t , ctx , sessionStore )
333358
@@ -341,7 +366,7 @@ func sessionSpecificEntries(t *testing.T, ctx context.Context, boltDB *BoltDB,
341366// entry for the local temp store, and one feature specific entry for the perm 
342367// local store. 
343368func  featureSpecificEntries (t  * testing.T , ctx  context.Context , boltDB  * BoltDB ,
344- 	sessionStore  session.Store ) [] * kvEntry  {
369+ 	sessionStore  session.Store ) * expectedResult  {
345370
346371	groupAlias  :=  getNewSessionAlias (t , ctx , sessionStore )
347372
@@ -359,11 +384,11 @@ func featureSpecificEntries(t *testing.T, ctx context.Context, boltDB *BoltDB,
359384// any entries when the entry set is more complex than just a single entry at 
360385// each level. 
361386func  allEntryCombinations (t  * testing.T , ctx  context.Context , boltDB  * BoltDB ,
362- 	sessionStore  session.Store ) [] * kvEntry  {
387+ 	sessionStore  session.Store ) * expectedResult  {
363388
364389	var  result  []* kvEntry 
365- 	add  :=  func (entry  [] * kvEntry ) {
366- 		result  =  append (result , entry ... )
390+ 	add  :=  func (entry  * expectedResult ) {
391+ 		result  =  append (result , entry .kvEntries . UnwrapOrFail ( t ) . ..
367392	}
368393
369394	// First lets create standard entries at all levels, which represents 
@@ -444,7 +469,9 @@ func allEntryCombinations(t *testing.T, ctx context.Context, boltDB *BoltDB,
444469		fn .Some (testFeatureName ), testEntryKey4 , emptyValue ,
445470	))
446471
447- 	return  result 
472+ 	return  & expectedResult {
473+ 		kvEntries : fn .Some (result ),
474+ 	}
448475}
449476
450477func  getNewSessionAlias (t  * testing.T , ctx  context.Context ,
@@ -465,7 +492,7 @@ func getNewSessionAlias(t *testing.T, ctx context.Context,
465492func  insertTempAndPermEntry (t  * testing.T , ctx  context.Context ,
466493	boltDB  * BoltDB , ruleName  string , groupAlias  fn.Option [[]byte ],
467494	featureNameOpt  fn.Option [string ], entryKey  string ,
468- 	entryValue  []byte ) [] * kvEntry  {
495+ 	entryValue  []byte ) * expectedResult  {
469496
470497	tempKvEntry  :=  & kvEntry {
471498		ruleName :    ruleName ,
@@ -489,7 +516,9 @@ func insertTempAndPermEntry(t *testing.T, ctx context.Context,
489516
490517	insertKvEntry (t , ctx , boltDB , permKvEntry )
491518
492- 	return  []* kvEntry {tempKvEntry , permKvEntry }
519+ 	return  & expectedResult {
520+ 		kvEntries : fn .Some ([]* kvEntry {tempKvEntry , permKvEntry }),
521+ 	}
493522}
494523
495524// insertKvEntry populates the kv store with passed entry, and asserts that the 
@@ -538,7 +567,7 @@ func insertKvEntry(t *testing.T, ctx context.Context,
538567// across all possible combinations of different levels of entries in the kv 
539568// store. All values and different bucket names are randomly generated. 
540569func  randomKVEntries (t  * testing.T , ctx  context.Context ,
541- 	boltDB  * BoltDB , sessionStore  session.Store ) [] * kvEntry  {
570+ 	boltDB  * BoltDB , sessionStore  session.Store ) * expectedResult  {
542571
543572	var  (
544573		// We set the number of entries to insert to 1000, as that 
@@ -649,7 +678,9 @@ func randomKVEntries(t *testing.T, ctx context.Context,
649678		insertedEntries  =  append (insertedEntries , entry )
650679	}
651680
652- 	return  insertedEntries 
681+ 	return  & expectedResult {
682+ 		kvEntries : fn .Some (insertedEntries ),
683+ 	}
653684}
654685
655686// randomString generates a random string of the passed length n. 
0 commit comments