Skip to content

Commit

Permalink
Do not leave db-files garbage behind
Browse files Browse the repository at this point in the history
  • Loading branch information
lzap authored and ezr-ondrej committed Apr 15, 2024
1 parent 2599e6b commit eac8502
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 22 deletions.
3 changes: 2 additions & 1 deletion cmd/cleanup/cleanupdevices/cleanupdevices_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion cmd/cleanup/cleanupimages/cleanupimages_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion cmd/cleanup/deleteimages/deleteimages_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func TestMigrate(t *testing.T) {
RegisterFailHandler(Fail)
dbName := setupTestDB()
defer tearDownTestDB(dbName)

RunSpecs(t, "Migrate device groups Suite")
}

Expand Down
1 change: 1 addition & 0 deletions cmd/migraterepos/migraterepos/migraterepos_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func TestMigrate(t *testing.T) {
RegisterFailHandler(Fail)
dbName := setupTestDB()
defer tearDownTestDB(dbName)

RunSpecs(t, "Migrate custom repositories Suite")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func TestPostMigrate(t *testing.T) {
RegisterFailHandler(Fail)
dbName := setupTestDB()
defer tearDownTestDB(dbName)

RunSpecs(t, "Migrate custom repositories Suite")
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/migraterepos/repairrepos/repairrepos_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 6 additions & 3 deletions pkg/db/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions pkg/models/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions pkg/routes/common/filters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 6 additions & 5 deletions pkg/routes/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions pkg/services/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pkg/services/update/update_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import (
func TestDevices(t *testing.T) {
RegisterFailHandler(Fail)
setUp()
defer tearDown()

RunSpecs(t, "Update Suite")
tearDown()
}

var dbName string
Expand Down

0 comments on commit eac8502

Please sign in to comment.