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
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/oplog"
|
||||
"github.com/hashicorp/go-uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_Utils(t *testing.T) {
|
||||
@@ -21,12 +22,12 @@ func Test_Utils(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestVerifyOplogEntry(t *testing.T) {
|
||||
db, _ := TestSetup(t, "postgres")
|
||||
d, _ := TestSetup(t, "postgres")
|
||||
assert := assert.New(t)
|
||||
TestCreateTables(t, db)
|
||||
TestCreateTables(t, d)
|
||||
|
||||
t.Run("valid", func(t *testing.T) {
|
||||
rw := Db{underlying: db}
|
||||
rw := New(d)
|
||||
id, err := uuid.GenerateUUID()
|
||||
assert.NoError(err)
|
||||
user, err := db_test.NewTestUser()
|
||||
@@ -51,14 +52,14 @@ func TestVerifyOplogEntry(t *testing.T) {
|
||||
err = rw.LookupByPublicId(context.Background(), foundUser)
|
||||
assert.NoError(err)
|
||||
assert.Equal(foundUser.Id, user.Id)
|
||||
err = TestVerifyOplog(t, &rw, user.PublicId, WithOperation(oplog.OpType_OP_TYPE_CREATE), WithCreateNotBefore(5*time.Second))
|
||||
err = TestVerifyOplog(t, rw, user.PublicId, WithOperation(oplog.OpType_OP_TYPE_CREATE), WithCreateNotBefore(5*time.Second))
|
||||
assert.NoError(err)
|
||||
})
|
||||
t.Run("should-fail", func(t *testing.T) {
|
||||
rw := Db{underlying: db}
|
||||
rw := New(d)
|
||||
id, err := uuid.GenerateUUID()
|
||||
assert.NoError(err)
|
||||
err = TestVerifyOplog(t, &rw, id)
|
||||
err = TestVerifyOplog(t, rw, id)
|
||||
assert.Error(err)
|
||||
})
|
||||
}
|
||||
@@ -121,3 +122,21 @@ func TestWithCreateNotBefore(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_TestDeleteWhere(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
d, _ := TestSetup(t, "postgres")
|
||||
TestCreateTables(t, d)
|
||||
user, err := db_test.NewTestUser()
|
||||
assert.NoError(err)
|
||||
id, err := uuid.GenerateUUID()
|
||||
assert.NoError(err)
|
||||
user.Name = "foo-" + id
|
||||
rw := New(d)
|
||||
err = rw.Create(
|
||||
context.Background(),
|
||||
user,
|
||||
)
|
||||
require.NoError(err)
|
||||
TestDeleteWhere(t, d, user, "1 = ?", 1)
|
||||
}
|
||||
Reference in new issue
Block a user