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:
Jim authored and GitHub committed 2021-09-30 09:17:27 -04:00
1 parent 136ac00b49
commit 8d6dee09a9
77 files changed
+441 -321

No files matched your search

+4 -5
View File
@@ -7,13 +7,12 @@ import (
"github.com/hashicorp/boundary/internal/db"
"github.com/stretchr/testify/assert"
"gorm.io/gorm"
)
// TestCatalogs creates count number of static host catalogs to the provided DB
// with the provided scope id. If any errors are encountered during the creation of
// the host catalog, the test will fail.
func TestCatalogs(t *testing.T, conn *gorm.DB, scopeId string, count int) []*HostCatalog {
func TestCatalogs(t *testing.T, conn *db.DB, scopeId string, count int) []*HostCatalog {
t.Helper()
assert := assert.New(t)
var cats []*HostCatalog
@@ -37,7 +36,7 @@ func TestCatalogs(t *testing.T, conn *gorm.DB, scopeId string, count int) []*Hos
// TestHosts creates count number of static hosts to the provided DB
// with the provided catalog id. The catalog must have been created previously.
// If any errors are encountered during the creation of the host, the test will fail.
func TestHosts(t *testing.T, conn *gorm.DB, catalogId string, count int) []*Host {
func TestHosts(t *testing.T, conn *db.DB, catalogId string, count int) []*Host {
t.Helper()
assert := assert.New(t)
var hosts []*Host
@@ -63,7 +62,7 @@ func TestHosts(t *testing.T, conn *gorm.DB, catalogId string, count int) []*Host
// TestSets creates count number of static host sets in the provided DB
// with the provided catalog id. The catalog must have been created
// previously. The test will fail if any errors are encountered.
func TestSets(t *testing.T, conn *gorm.DB, catalogId string, count int) []*HostSet {
func TestSets(t *testing.T, conn *db.DB, catalogId string, count int) []*HostSet {
t.Helper()
assert := assert.New(t)
var sets []*HostSet
@@ -88,7 +87,7 @@ func TestSets(t *testing.T, conn *gorm.DB, catalogId string, count int) []*HostS
// TestSetMembers adds hosts to the specified setId in the provided DB.
// The set and hosts must have been created previously and belong to the
// same catalog. The test will fail if any errors are encountered.
func TestSetMembers(t *testing.T, conn *gorm.DB, setId string, hosts []*Host) []*HostSetMember {
func TestSetMembers(t *testing.T, conn *db.DB, setId string, hosts []*Host) []*HostSetMember {
t.Helper()
assert := assert.New(t)