refactor: Update internal/db and oplog to use go-dbw package for database operations. (#1785)

* chore: Add new dbw dependency

* refactor: Convert to use dbw.DB

* refactor (db): Change GetTicket(...) signature

* feature (db tests): Added TestDeleteWhere(...)
Adding this allows us to eliminate a leak of the gorm library

* refactor: Add ctx to ScanRows(...) signature
This is required to refactor all the deprecated errors pkg calls.
This refactor required adding a context to quite a few call chains
and in particular the job scheduler bits

* feature (db/tests): Add support for test opt: WithTestLogLevel(...)
This test only option allows callers to specify a log level for the
underlying db package (where supported/applicable) when calling
TestSetup(...)

* refactor (db): Simplify Db type
Only store the underlying *DB and create the *RW on demand when
needed.

* refactor (oplog): Port to using dbw pkg for db operations

* refactor (db): Remove gormDB(...) func

* tests (db): Add unit tests for TestDeleteWhere(...)

* chore: make fmt changes to formatting
This commit is contained in:
Jim authored and GitHub committed 2022-01-05 14:38:38 -05:00
1 parent 002d004114
commit 591ec476e7
160 files changed
+4369 -3164

No files matched your search

+1 -3
View File
@@ -9,15 +9,13 @@ import (
"github.com/hashicorp/boundary/internal/iam"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gorm.io/gorm/logger"
)
func TestHostSet_New(t *testing.T) {
conn, _ := db.TestSetup(t, "postgres")
conn, _ := db.TestSetup(t, "postgres", db.WithTestLogLevel(t, db.SilentTestLogLevel))
wrapper := db.TestWrapper(t)
_, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper))
cat := testCatalog(t, conn, prj.PublicId)
conn.Logger.LogMode(logger.Silent)
type args struct {
catalogId string
opts []Option
+1 -3
View File
@@ -9,16 +9,14 @@ import (
"github.com/hashicorp/boundary/internal/iam"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gorm.io/gorm/logger"
)
func TestHost_New(t *testing.T) {
conn, _ := db.TestSetup(t, "postgres")
conn, _ := db.TestSetup(t, "postgres", db.WithTestLogLevel(t, db.SilentTestLogLevel))
wrapper := db.TestWrapper(t)
_, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper))
cat := testCatalog(t, conn, prj.PublicId)
conn.Logger.LogMode(logger.Silent)
type args struct {
catalogId string
opts []Option
@@ -270,7 +270,7 @@ func TestStaticHostSetMember_ImmutableFields(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
assert, require := assert.New(t), require.New(t)
orig := new.testCloneHostSetMember()
err = w.LookupWhere(context.Background(), orig, "host_id = ? and set_id = ?", orig.HostId, orig.SetId)
err = w.LookupWhere(context.Background(), orig, "host_id = ? and set_id = ?", []interface{}{orig.HostId, orig.SetId})
require.NoError(err)
rowsUpdated, err := w.Update(context.Background(), tt.update, tt.fieldMask, nil, db.WithSkipVetForWrite(true))
@@ -278,7 +278,7 @@ func TestStaticHostSetMember_ImmutableFields(t *testing.T) {
assert.Equal(0, rowsUpdated)
after := new.testCloneHostSetMember()
err = w.LookupWhere(context.Background(), after, "host_id = ? and set_id = ?", after.HostId, after.SetId)
err = w.LookupWhere(context.Background(), after, "host_id = ? and set_id = ?", []interface{}{after.HostId, after.SetId})
require.NoError(err)
assert.True(proto.Equal(orig, after))
@@ -109,7 +109,7 @@ func updateVersion(ctx context.Context, w db.Writer, wrapper wrapping.Wrapper, m
msgs = append(msgs, setMsg)
// Write oplog
ticket, err := w.GetTicket(set)
ticket, err := w.GetTicket(ctx, set)
if err != nil {
return errors.Wrap(ctx, err, op, errors.WithMsg("unable to get ticket"))
}
@@ -356,7 +356,7 @@ func (r *Repository) changes(ctx context.Context, setId string, hostIds []string
var changes []*change
for rows.Next() {
var chg change
if err := r.reader.ScanRows(rows, &chg); err != nil {
if err := r.reader.ScanRows(ctx, rows, &chg); err != nil {
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("scan row failed"))
}
changes = append(changes, &chg)