Skip to content

Commit 93d8bf9

Browse files
committed
Import order
1 parent 7d4b7ea commit 93d8bf9

File tree

3 files changed

+16
-31
lines changed

3 files changed

+16
-31
lines changed

coderd/database/dbauthz/dbauthz.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ import (
1515
"github.com/coder/coder/coderd/rbac"
1616
)
1717

18-
// IsDBAuthzStore is provided for unit testing only.
19-
type IsDBAuthzStore interface {
20-
UnderlyingDatabase() database.Store
21-
}
22-
2318
var _ database.Store = (*querier)(nil)
2419

2520
// NoActorError wraps ErrNoRows for the api to return a 404. This is the correct
@@ -104,12 +99,6 @@ func New(db database.Store, authorizer rbac.Authorizer, logger slog.Logger) data
10499
}
105100
}
106101

107-
// UnderlyingDatabase is dangerous and should not be used. This is only provided to accommodate some
108-
// unit testing that has to manipulate the database directly.
109-
func (q *querier) UnderlyingDatabase() database.Store {
110-
return q.db
111-
}
112-
113102
// authorizeContext is a helper function to authorize an action on an object.
114103
func (q *querier) authorizeContext(ctx context.Context, action rbac.Action, object rbac.Objecter) error {
115104
act, ok := ActorFromContext(ctx)

coderd/database/dbgen/generator.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,15 @@ import (
1111
"testing"
1212
"time"
1313

14-
"github.com/coder/coder/coderd/database/dbtype"
15-
16-
"github.com/coder/coder/coderd/database/dbauthz"
17-
"github.com/coder/coder/coderd/rbac"
18-
1914
"github.com/google/uuid"
2015
"github.com/moby/moby/pkg/namesgenerator"
2116
"github.com/stretchr/testify/require"
2217
"github.com/tabbed/pqtype"
2318

2419
"github.com/coder/coder/coderd/database"
20+
"github.com/coder/coder/coderd/database/dbauthz"
21+
"github.com/coder/coder/coderd/database/dbtype"
22+
"github.com/coder/coder/coderd/rbac"
2523
"github.com/coder/coder/cryptorand"
2624
)
2725

@@ -277,10 +275,6 @@ func GroupMember(t testing.TB, db database.Store, orig database.GroupMember) dat
277275
// ProvisionerJob might not have all the correct values like CompletedAt and CancelledAt. This is because
278276
// the workspaceBuild is required to fetch those,
279277
func ProvisionerJob(t testing.TB, db database.Store, orig database.ProvisionerJob) database.ProvisionerJob {
280-
if dba, ok := db.(dbauthz.IsDBAuthzStore); ok {
281-
db = dba.UnderlyingDatabase()
282-
}
283-
284278
id := takeFirst(orig.ID, uuid.New())
285279
// Always set some tags to prevent Acquire from grabbing jobs it should not.
286280
if !orig.StartedAt.Time.IsZero() || orig.Tags == nil {

coderd/workspaces_test.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,19 @@ import (
99
"testing"
1010
"time"
1111

12-
"github.com/coder/coder/coderd/database/dbauthz"
13-
14-
"github.com/coder/coder/coderd/database/dbgen"
15-
1612
"github.com/google/uuid"
1713
"github.com/stretchr/testify/assert"
1814
"github.com/stretchr/testify/require"
1915

2016
"cdr.dev/slog"
2117
"cdr.dev/slog/sloggers/slogtest"
22-
2318
"github.com/coder/coder/agent"
2419
"github.com/coder/coder/coderd/audit"
2520
"github.com/coder/coder/coderd/coderdtest"
2621
"github.com/coder/coder/coderd/database"
22+
"github.com/coder/coder/coderd/database/dbauthz"
23+
"github.com/coder/coder/coderd/database/dbgen"
24+
"github.com/coder/coder/coderd/database/dbtestutil"
2725
"github.com/coder/coder/coderd/parameter"
2826
"github.com/coder/coder/coderd/rbac"
2927
"github.com/coder/coder/coderd/schedule"
@@ -562,32 +560,36 @@ func TestWorkspaceByOwnerAndName(t *testing.T) {
562560

563561
func TestWorkspaceFilterAllStatus(t *testing.T) {
564562
ctx := dbauthz.AsSystemRestricted(context.Background())
565-
client, _, api := coderdtest.NewWithAPI(t, &coderdtest.Options{})
563+
db, pubsub := dbtestutil.NewDB(t)
564+
client := coderdtest.New(t, &coderdtest.Options{
565+
Database: db,
566+
Pubsub: pubsub,
567+
})
566568

567569
owner := coderdtest.CreateFirstUser(t, client)
568570

569-
file := dbgen.File(t, api.Database, database.File{
571+
file := dbgen.File(t, db, database.File{
570572
CreatedBy: owner.UserID,
571573
})
572-
versionJob := dbgen.ProvisionerJob(t, api.Database, database.ProvisionerJob{
574+
versionJob := dbgen.ProvisionerJob(t, db, database.ProvisionerJob{
573575
OrganizationID: owner.OrganizationID,
574576
InitiatorID: owner.UserID,
575577
WorkerID: uuid.NullUUID{},
576578
FileID: file.ID,
577579
})
578-
version := dbgen.TemplateVersion(t, api.Database, database.TemplateVersion{
580+
version := dbgen.TemplateVersion(t, db, database.TemplateVersion{
579581
OrganizationID: owner.OrganizationID,
580582
JobID: versionJob.ID,
581583
CreatedBy: owner.UserID,
582584
})
583-
template := dbgen.Template(t, api.Database, database.Template{
585+
template := dbgen.Template(t, db, database.Template{
584586
OrganizationID: owner.OrganizationID,
585587
ActiveVersionID: version.ID,
586588
CreatedBy: owner.UserID,
587589
})
588590

589591
makeWorkspace := func(workspace database.Workspace, job database.ProvisionerJob, transition database.WorkspaceTransition) (database.Workspace, database.WorkspaceBuild, database.ProvisionerJob) {
590-
db := api.Database
592+
db := db
591593

592594
workspace.OwnerID = owner.UserID
593595
workspace.OrganizationID = owner.OrganizationID

0 commit comments

Comments
 (0)