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:
160 files changed
+4369
-3164
No files matched your search
@@ -9,17 +9,18 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/db/timestamp"
|
||||
"github.com/hashicorp/boundary/internal/oplog/oplog_test"
|
||||
"github.com/hashicorp/boundary/internal/oplog/store"
|
||||
"github.com/hashicorp/go-dbw"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
func Test_ImmutableFields(t *testing.T) {
|
||||
cleanup, db := setup(t)
|
||||
defer testCleanup(t, cleanup, db)
|
||||
testCtx := context.Background()
|
||||
db := setup(t)
|
||||
cipherer := testWrapper(t)
|
||||
|
||||
writer := &GormWriter{db}
|
||||
writer := &Writer{db}
|
||||
id := testId(t)
|
||||
u := oplog_test.TestUser{
|
||||
Name: "foo-" + id,
|
||||
@@ -32,13 +33,14 @@ func Test_ImmutableFields(t *testing.T) {
|
||||
}
|
||||
t.Log(&u2)
|
||||
|
||||
ticketer, err := NewGormTicketer(db, WithAggregateNames(true))
|
||||
ticketer, err := NewTicketer(testCtx, db, WithAggregateNames(true))
|
||||
require.NoError(t, err)
|
||||
|
||||
ticket, err := ticketer.GetTicket("default")
|
||||
ticket, err := ticketer.GetTicket(testCtx, "default")
|
||||
require.NoError(t, err)
|
||||
|
||||
new, err := NewEntry(
|
||||
testCtx,
|
||||
"test-users",
|
||||
Metadata{
|
||||
"key-only": nil,
|
||||
@@ -49,7 +51,7 @@ func Test_ImmutableFields(t *testing.T) {
|
||||
ticketer,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
err = new.WriteEntryWith(context.Background(), writer, ticket,
|
||||
err = new.WriteEntryWith(testCtx, writer, ticket,
|
||||
&Message{Message: &u, TypeName: "user", OpType: OpType_OP_TYPE_CREATE},
|
||||
&Message{Message: &u2, TypeName: "user", OpType: OpType_OP_TYPE_CREATE})
|
||||
require.NoError(t, err)
|
||||
@@ -119,16 +121,13 @@ func Test_ImmutableFields(t *testing.T) {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
orig := testCloneEntry(new)
|
||||
err = db.First(orig).Error
|
||||
require.NoError(err)
|
||||
require.NoError(dbw.New(db).LookupBy(testCtx, orig))
|
||||
|
||||
err := writer.Update(tt.update, tt.fieldMask, nil)
|
||||
_, err := dbw.New(writer.DB).Update(testCtx, tt.update, tt.fieldMask, nil)
|
||||
require.Error(err)
|
||||
|
||||
after := testCloneEntry(new)
|
||||
err = db.First(&after).Error
|
||||
require.NoError(err)
|
||||
|
||||
require.NoError(dbw.New(db).LookupBy(testCtx, after))
|
||||
assert.True(proto.Equal(orig, after))
|
||||
})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user