diff --git a/cmd/cleanup/cleanupdevices/cleanupdevices_suite_test.go b/cmd/cleanup/cleanupdevices/cleanupdevices_suite_test.go index 579f40870..1f567e4f1 100644 --- a/cmd/cleanup/cleanupdevices/cleanupdevices_suite_test.go +++ b/cmd/cleanup/cleanupdevices/cleanupdevices_suite_test.go @@ -17,8 +17,9 @@ import ( func TestMigrate(t *testing.T) { RegisterFailHandler(Fail) dbName := setupTestDB() + defer tearDownTestDB(dbName) + RunSpecs(t, "Cleanup devices storage Suite") - tearDownTestDB(dbName) } func setupTestDB() string { diff --git a/cmd/cleanup/cleanupimages/cleanupimages_suite_test.go b/cmd/cleanup/cleanupimages/cleanupimages_suite_test.go index be9b59edc..bb49268af 100644 --- a/cmd/cleanup/cleanupimages/cleanupimages_suite_test.go +++ b/cmd/cleanup/cleanupimages/cleanupimages_suite_test.go @@ -17,8 +17,9 @@ import ( func TestMigrate(t *testing.T) { RegisterFailHandler(Fail) dbName := setupTestDB() + defer tearDownTestDB(dbName) + RunSpecs(t, "Cleanup images storage Suite") - tearDownTestDB(dbName) } func setupTestDB() string { diff --git a/cmd/cleanup/cleanuporphancommits/cleanuporphancommits_suite_test.go b/cmd/cleanup/cleanuporphancommits/cleanuporphancommits_suite_test.go index 5382f314e..ec0c45a76 100644 --- a/cmd/cleanup/cleanuporphancommits/cleanuporphancommits_suite_test.go +++ b/cmd/cleanup/cleanuporphancommits/cleanuporphancommits_suite_test.go @@ -17,8 +17,9 @@ import ( func TestCleanupOrphanCommits(t *testing.T) { RegisterFailHandler(Fail) dbName := setupTestDB() + defer tearDownTestDB(dbName) + RunSpecs(t, "Cleanup orphan commits Suite") - tearDownTestDB(dbName) } func setupTestDB() string { diff --git a/cmd/cleanup/deleteimages/deleteimages_suite_test.go b/cmd/cleanup/deleteimages/deleteimages_suite_test.go index 9aede083e..b6e16923b 100644 --- a/cmd/cleanup/deleteimages/deleteimages_suite_test.go +++ b/cmd/cleanup/deleteimages/deleteimages_suite_test.go @@ -17,8 +17,9 @@ import ( func TestMigrate(t *testing.T) { RegisterFailHandler(Fail) dbName := setupTestDB() + defer tearDownTestDB(dbName) + RunSpecs(t, "Cleanup images storage Suite") - tearDownTestDB(dbName) } func setupTestDB() string { diff --git a/cmd/migrategroups/migrategroups/migrategroups_suite_test.go b/cmd/migrategroups/migrategroups/migrategroups_suite_test.go index f95bc6649..6ddb003d3 100644 --- a/cmd/migrategroups/migrategroups/migrategroups_suite_test.go +++ b/cmd/migrategroups/migrategroups/migrategroups_suite_test.go @@ -18,6 +18,7 @@ func TestMigrate(t *testing.T) { RegisterFailHandler(Fail) dbName := setupTestDB() defer tearDownTestDB(dbName) + RunSpecs(t, "Migrate device groups Suite") } diff --git a/cmd/migraterepos/migraterepos/migraterepos_suite_test.go b/cmd/migraterepos/migraterepos/migraterepos_suite_test.go index cf880b5c1..73dcba10e 100644 --- a/cmd/migraterepos/migraterepos/migraterepos_suite_test.go +++ b/cmd/migraterepos/migraterepos/migraterepos_suite_test.go @@ -18,6 +18,7 @@ func TestMigrate(t *testing.T) { RegisterFailHandler(Fail) dbName := setupTestDB() defer tearDownTestDB(dbName) + RunSpecs(t, "Migrate custom repositories Suite") } diff --git a/cmd/migraterepos/postmigraterepos/postmigraterepos_suite_test.go b/cmd/migraterepos/postmigraterepos/postmigraterepos_suite_test.go index f784fb3b0..66bdebc5f 100644 --- a/cmd/migraterepos/postmigraterepos/postmigraterepos_suite_test.go +++ b/cmd/migraterepos/postmigraterepos/postmigraterepos_suite_test.go @@ -18,6 +18,7 @@ func TestPostMigrate(t *testing.T) { RegisterFailHandler(Fail) dbName := setupTestDB() defer tearDownTestDB(dbName) + RunSpecs(t, "Migrate custom repositories Suite") } diff --git a/cmd/migraterepos/repairrepos/repairrepos_suite_test.go b/cmd/migraterepos/repairrepos/repairrepos_suite_test.go index df3575958..579d41091 100644 --- a/cmd/migraterepos/repairrepos/repairrepos_suite_test.go +++ b/cmd/migraterepos/repairrepos/repairrepos_suite_test.go @@ -17,8 +17,9 @@ import ( func TestMigrate(t *testing.T) { RegisterFailHandler(Fail) dbName := setupTestDB() + defer tearDownTestDB(dbName) + RunSpecs(t, "Repair custom repositories Suite") - tearDownTestDB(dbName) } func setupTestDB() string { diff --git a/pkg/db/main_test.go b/pkg/db/main_test.go index c2822da8b..3863ccc21 100644 --- a/pkg/db/main_test.go +++ b/pkg/db/main_test.go @@ -15,10 +15,13 @@ import ( // This will set up the test database and run the tests for whole package func TestMain(m *testing.M) { + rc := 0 + defer func() { os.Exit(rc) }() + setupTestDB() - retCode := m.Run() - tearDownTestDB() - os.Exit(retCode) + defer tearDownTestDB() + + rc = m.Run() } var dbName string diff --git a/pkg/models/main_test.go b/pkg/models/main_test.go index 5f0be879b..b32097ea9 100644 --- a/pkg/models/main_test.go +++ b/pkg/models/main_test.go @@ -16,10 +16,13 @@ import ( ) func TestMain(m *testing.M) { + rc := 0 + defer func() { os.Exit(rc) }() + setUp() - retCode := m.Run() - tearDown() - os.Exit(retCode) + defer tearDown() + + rc = m.Run() } var dbName string diff --git a/pkg/routes/common/filters_test.go b/pkg/routes/common/filters_test.go index bc96766b8..482e44a13 100644 --- a/pkg/routes/common/filters_test.go +++ b/pkg/routes/common/filters_test.go @@ -64,11 +64,18 @@ func setUp() { } func TestMain(m *testing.M) { + rc := 0 + defer func() { os.Exit(rc) }() + setUp() - retCode := m.Run() + defer tearDown() + + rc = m.Run() db.DB.Exec("DELETE FROM images") +} + +func tearDown() { os.Remove(dbName) - os.Exit(retCode) } func TestContainFilterHandler(t *testing.T) { diff --git a/pkg/routes/main_test.go b/pkg/routes/main_test.go index 8f92dee16..113509c77 100644 --- a/pkg/routes/main_test.go +++ b/pkg/routes/main_test.go @@ -44,12 +44,13 @@ var ( ) func TestMain(m *testing.M) { + rc := 0 + defer func() { os.Exit(rc) }() + setUp() - retCode := m.Run() - defer func(exitCode int) { - tearDown() - os.Exit(exitCode) - }(retCode) + defer tearDown() + + rc = m.Run() } var dbName string diff --git a/pkg/services/main_test.go b/pkg/services/main_test.go index 283f9ec3d..0417021f0 100644 --- a/pkg/services/main_test.go +++ b/pkg/services/main_test.go @@ -16,10 +16,13 @@ import ( // This will setup the test database and run the tests for whole package func TestMain(m *testing.M) { + rc := 0 + defer func() { os.Exit(rc) }() + setupTestDB() - retCode := m.Run() - tearDownTestDB() - os.Exit(retCode) + defer tearDownTestDB() + + rc = m.Run() } var dbName string diff --git a/pkg/services/update/update_suite_test.go b/pkg/services/update/update_suite_test.go index dc9fcf88e..fcebbe11b 100644 --- a/pkg/services/update/update_suite_test.go +++ b/pkg/services/update/update_suite_test.go @@ -20,8 +20,9 @@ import ( func TestDevices(t *testing.T) { RegisterFailHandler(Fail) setUp() + defer tearDown() + RunSpecs(t, "Update Suite") - tearDown() } var dbName string