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
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/db"
|
||||
"github.com/hashicorp/boundary/internal/kms"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -26,7 +27,7 @@ func TestController_New(t *testing.T) {
|
||||
require.NoError(err)
|
||||
|
||||
// this tests a scenario where there is NOT an audit DEK
|
||||
require.NoError(c.conf.Server.Database.Where("1=1").Delete(kms.AllocAuditKey()).Error)
|
||||
db.TestDeleteWhere(t, c.conf.Server.Database, func() interface{} { i := kms.AllocAuditKey(); return &i }(), "1=1")
|
||||
_, err = New(testCtx, conf)
|
||||
require.NoError(err)
|
||||
})
|
||||
|
||||
@@ -150,8 +150,8 @@ func errorInterceptor(
|
||||
return func(interceptorCtx context.Context,
|
||||
req interface{},
|
||||
_ *grpc.UnaryServerInfo,
|
||||
handler grpc.UnaryHandler) (interface{}, error) {
|
||||
|
||||
handler grpc.UnaryHandler) (interface{}, error,
|
||||
) {
|
||||
// call the handler...
|
||||
h, handlerErr := handler(interceptorCtx, req)
|
||||
|
||||
@@ -201,8 +201,8 @@ func statusCodeInterceptor(
|
||||
return func(interceptorCtx context.Context,
|
||||
req interface{},
|
||||
_ *grpc.UnaryServerInfo,
|
||||
handler grpc.UnaryHandler) (interface{}, error) {
|
||||
|
||||
handler grpc.UnaryHandler) (interface{}, error,
|
||||
) {
|
||||
// call the handler...
|
||||
h, handlerErr := handler(interceptorCtx, req)
|
||||
|
||||
@@ -237,8 +237,8 @@ func auditRequestInterceptor(
|
||||
return func(interceptorCtx context.Context,
|
||||
req interface{},
|
||||
_ *grpc.UnaryServerInfo,
|
||||
handler grpc.UnaryHandler) (interface{}, error) {
|
||||
|
||||
handler grpc.UnaryHandler) (interface{}, error,
|
||||
) {
|
||||
if msg, ok := req.(proto.Message); ok {
|
||||
if err := event.WriteAudit(interceptorCtx, op, event.WithRequest(&event.Request{Details: msg})); err != nil {
|
||||
return req, status.Errorf(codes.Internal, "unable to write request msg audit: %s", err)
|
||||
@@ -256,8 +256,8 @@ func auditResponseInterceptor(
|
||||
return func(interceptorCtx context.Context,
|
||||
req interface{},
|
||||
_ *grpc.UnaryServerInfo,
|
||||
handler grpc.UnaryHandler) (interface{}, error) {
|
||||
|
||||
handler grpc.UnaryHandler) (interface{}, error,
|
||||
) {
|
||||
// call the handler...
|
||||
resp, err := handler(interceptorCtx, req)
|
||||
|
||||
|
||||
@@ -492,7 +492,6 @@ func Test_workerRequestInfoInterceptor(t *testing.T) {
|
||||
wantRequestErrMatch *errors.Template
|
||||
wantRequestErrContains string
|
||||
}{
|
||||
|
||||
{
|
||||
name: "missing-eventer",
|
||||
requestCtx: requestCtx,
|
||||
|
||||
@@ -68,7 +68,9 @@ func (j *sessionCleanupJob) Description() string {
|
||||
// connections as soon as a worker has not reported in for a long
|
||||
// enough time. Only one job will ever run at once, so there is no
|
||||
// reason why it cannot run again immediately.
|
||||
func (j *sessionCleanupJob) NextRunIn() (time.Duration, error) { return time.Second, nil }
|
||||
func (j *sessionCleanupJob) NextRunIn(_ context.Context) (time.Duration, error) {
|
||||
return time.Second, nil
|
||||
}
|
||||
|
||||
// Status returns the status of the running job.
|
||||
func (j *sessionCleanupJob) Status() scheduler.JobStatus {
|
||||
|
||||
Reference in new issue
Block a user