refact: Add db.DB wrapper and refact all test fixtures to use it. (#1535)
* refact: Changes required for gorm v2 * refact: Add db.DB wrapper and refact all test fixtures to use it Stop leaking the gorm abstraction within our unit tests. * refact: Migrate direct calls to pq to pgx driver The refactor will remove the remaining direct dependencies on the pq driver which has been deprecated in favor of the pgx driver. It includes the addition of common.SqlOpen which is a wrapper around sql.Open, which is needed to deal with the driver name changing from "postgres" to "pgx" but in our code base the dialect and driver are synonyms.
This commit is contained in:
77 files changed
+441
-321
No files matched your search
@@ -17,12 +17,11 @@ import (
|
||||
wrapping "github.com/hashicorp/go-kms-wrapping"
|
||||
"github.com/hashicorp/go-kms-wrapping/wrappers/aead"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/logger"
|
||||
)
|
||||
|
||||
// setup the tests (initialize the database one-time and intialized testDatabaseURL). Do not close the returned db.
|
||||
func TestSetup(t *testing.T, dialect string, opt ...TestOption) (*gorm.DB, string) {
|
||||
func TestSetup(t *testing.T, dialect string, opt ...TestOption) (*DB, string) {
|
||||
var cleanup func() error
|
||||
var url string
|
||||
var err error
|
||||
@@ -57,7 +56,7 @@ func TestSetup(t *testing.T, dialect string, opt ...TestOption) (*gorm.DB, strin
|
||||
}
|
||||
db.Logger.LogMode(logger.Error)
|
||||
t.Cleanup(func() {
|
||||
sqlDB, err := db.DB()
|
||||
sqlDB, err := db.SqlDB(ctx)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, sqlDB.Close(), "Got error closing gorm db.")
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user