Pushing test db cleanup up to where the database objects are created using t.Cleanup. (#166)

This commit is contained in:
Todd Knight authored and GitHub committed 2020-07-06 10:15:01 -07:00
1 parent 316b250a24
commit bb4a185412
25 files changed
+110 -793

No files matched your search

+10 -3
View File
@@ -13,19 +13,26 @@ import (
"github.com/hashicorp/watchtower/internal/oplog"
"github.com/hashicorp/watchtower/internal/oplog/store"
"github.com/jinzhu/gorm"
"github.com/stretchr/testify/assert"
)
// setup the tests (initialize the database one-time and intialized testDatabaseURL)
func TestSetup(t *testing.T, dialect string) (func() error, *gorm.DB, string) {
// setup the tests (initialize the database one-time and intialized testDatabaseURL). Do not close the returned db.
func TestSetup(t *testing.T, dialect string) (*gorm.DB, string) {
cleanup, url, _, err := InitDbInDocker(dialect)
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() {
assert.NoError(t, cleanup(), "Got error cleaning up db in docker.")
})
db, err := gorm.Open(dialect, url)
if err != nil {
t.Fatal(err)
}
return cleanup, db, url
t.Cleanup(func() {
assert.NoError(t, db.Close(), "Got error closing gorm db.")
})
return db, url
}
// TestWrapper initializes an AEAD wrapping.Wrapper for testing the oplog