mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
chore: remove New----Builder from dbfake function names (#10882)
Drop "New" and "Builder" from the function names, in favor of the top-level resource created. This shortens tests and gives a nice syntax. Since everything is a builder, the prefix and suffix don't add much value and just make things harder to read. I've also chosen to leave `Do()` as the function to insert into the database. Even though it's a builder pattern, I fear `.Build()` might be confusing with Workspace Builds. One other idea is `Insert()` but if we later add dbfake functions that update, this might be inconsistent.
This commit is contained in:
@ -36,7 +36,7 @@ type WorkspaceResponse struct {
|
||||
AgentToken string
|
||||
}
|
||||
|
||||
func NewWorkspaceBuilder(t testing.TB, db database.Store) WorkspaceBuilder {
|
||||
func Workspace(t testing.TB, db database.Store) WorkspaceBuilder {
|
||||
return WorkspaceBuilder{t: t, db: db}
|
||||
}
|
||||
|
||||
@ -82,7 +82,7 @@ func (b WorkspaceBuilder) Do() WorkspaceResponse {
|
||||
r.Workspace = dbgen.Workspace(b.t, b.db, b.seed)
|
||||
if b.agentToken != "" {
|
||||
r.AgentToken = b.agentToken
|
||||
r.Build = NewWorkspaceBuildBuilder(b.t, b.db, r.Workspace).
|
||||
r.Build = WorkspaceBuild(b.t, b.db, r.Workspace).
|
||||
Resource(b.resources...).
|
||||
Do()
|
||||
}
|
||||
@ -98,7 +98,7 @@ type WorkspaceBuildBuilder struct {
|
||||
resources []*sdkproto.Resource
|
||||
}
|
||||
|
||||
func NewWorkspaceBuildBuilder(t testing.TB, db database.Store, ws database.Workspace) WorkspaceBuildBuilder {
|
||||
func WorkspaceBuild(t testing.TB, db database.Store, ws database.Workspace) WorkspaceBuildBuilder {
|
||||
return WorkspaceBuildBuilder{t: t, db: db, ws: ws}
|
||||
}
|
||||
|
||||
@ -187,11 +187,11 @@ func (b WorkspaceBuildBuilder) Do() database.WorkspaceBuild {
|
||||
Valid: true,
|
||||
},
|
||||
})
|
||||
NewProvisionerJobResourcesBuilder(b.t, b.db, jobID, b.seed.Transition, b.resources...).Do()
|
||||
ProvisionerJobResources(b.t, b.db, jobID, b.seed.Transition, b.resources...).Do()
|
||||
b.seed.TemplateVersionID = templateVersion.ID
|
||||
}
|
||||
build := dbgen.WorkspaceBuild(b.t, b.db, b.seed)
|
||||
NewProvisionerJobResourcesBuilder(b.t, b.db, job.ID, b.seed.Transition, b.resources...).Do()
|
||||
ProvisionerJobResources(b.t, b.db, job.ID, b.seed.Transition, b.resources...).Do()
|
||||
if b.ps != nil {
|
||||
err = b.ps.Publish(codersdk.WorkspaceNotifyChannel(build.WorkspaceID), []byte{})
|
||||
require.NoError(b.t, err)
|
||||
@ -207,8 +207,8 @@ type ProvisionerJobResourcesBuilder struct {
|
||||
resources []*sdkproto.Resource
|
||||
}
|
||||
|
||||
// NewProvisionerJobResourcesBuilder inserts a series of resources into a provisioner job.
|
||||
func NewProvisionerJobResourcesBuilder(
|
||||
// ProvisionerJobResources inserts a series of resources into a provisioner job.
|
||||
func ProvisionerJobResources(
|
||||
t testing.TB, db database.Store, jobID uuid.UUID, transition database.WorkspaceTransition, resources ...*sdkproto.Resource,
|
||||
) ProvisionerJobResourcesBuilder {
|
||||
return ProvisionerJobResourcesBuilder{
|
||||
|
@ -47,7 +47,7 @@ func TestWorkspaceAgent(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
anotherClient, anotherUser := coderdtest.CreateAnotherUser(t, client, user.OrganizationID)
|
||||
|
||||
r := dbfake.NewWorkspaceBuilder(t, db).Seed(database.Workspace{
|
||||
r := dbfake.Workspace(t, db).Seed(database.Workspace{
|
||||
OrganizationID: user.OrganizationID,
|
||||
OwnerID: anotherUser.ID,
|
||||
}).WithAgent(func(agents []*proto.Agent) []*proto.Agent {
|
||||
@ -69,7 +69,7 @@ func TestWorkspaceAgent(t *testing.T) {
|
||||
client, db := coderdtest.NewWithDatabase(t, nil)
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
tmpDir := t.TempDir()
|
||||
r := dbfake.NewWorkspaceBuilder(t, db).Seed(database.Workspace{
|
||||
r := dbfake.Workspace(t, db).Seed(database.Workspace{
|
||||
OrganizationID: user.OrganizationID,
|
||||
OwnerID: user.UserID,
|
||||
}).WithAgent(func(agents []*proto.Agent) []*proto.Agent {
|
||||
@ -97,7 +97,7 @@ func TestWorkspaceAgent(t *testing.T) {
|
||||
|
||||
wantTroubleshootingURL := "https://example.com/troubleshoot"
|
||||
|
||||
r := dbfake.NewWorkspaceBuilder(t, db).Seed(database.Workspace{
|
||||
r := dbfake.Workspace(t, db).Seed(database.Workspace{
|
||||
OrganizationID: user.OrganizationID,
|
||||
OwnerID: user.UserID,
|
||||
}).WithAgent(func(agents []*proto.Agent) []*proto.Agent {
|
||||
@ -138,7 +138,7 @@ func TestWorkspaceAgent(t *testing.T) {
|
||||
PortForwardingHelper: true,
|
||||
SshHelper: true,
|
||||
}
|
||||
r := dbfake.NewWorkspaceBuilder(t, db).Seed(database.Workspace{
|
||||
r := dbfake.Workspace(t, db).Seed(database.Workspace{
|
||||
OrganizationID: user.OrganizationID,
|
||||
OwnerID: user.UserID,
|
||||
}).WithAgent(func(agents []*proto.Agent) []*proto.Agent {
|
||||
@ -171,7 +171,7 @@ func TestWorkspaceAgent(t *testing.T) {
|
||||
apps.WebTerminal = false
|
||||
|
||||
// Creating another workspace is easier
|
||||
r = dbfake.NewWorkspaceBuilder(t, db).Seed(database.Workspace{
|
||||
r = dbfake.Workspace(t, db).Seed(database.Workspace{
|
||||
OrganizationID: user.OrganizationID,
|
||||
OwnerID: user.UserID,
|
||||
}).WithAgent(func(agents []*proto.Agent) []*proto.Agent {
|
||||
@ -195,7 +195,7 @@ func TestWorkspaceAgentLogs(t *testing.T) {
|
||||
ctx := testutil.Context(t, testutil.WaitMedium)
|
||||
client, db := coderdtest.NewWithDatabase(t, nil)
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
r := dbfake.NewWorkspaceBuilder(t, db).Seed(database.Workspace{
|
||||
r := dbfake.Workspace(t, db).Seed(database.Workspace{
|
||||
OrganizationID: user.OrganizationID,
|
||||
OwnerID: user.UserID,
|
||||
}).WithAgent().Do()
|
||||
@ -237,7 +237,7 @@ func TestWorkspaceAgentLogs(t *testing.T) {
|
||||
ctx := testutil.Context(t, testutil.WaitMedium)
|
||||
client, db := coderdtest.NewWithDatabase(t, nil)
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
r := dbfake.NewWorkspaceBuilder(t, db).Seed(database.Workspace{
|
||||
r := dbfake.Workspace(t, db).Seed(database.Workspace{
|
||||
OrganizationID: user.OrganizationID,
|
||||
OwnerID: user.UserID,
|
||||
}).WithAgent().Do()
|
||||
@ -279,7 +279,7 @@ func TestWorkspaceAgentLogs(t *testing.T) {
|
||||
ctx := testutil.Context(t, testutil.WaitMedium)
|
||||
client, db := coderdtest.NewWithDatabase(t, nil)
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
r := dbfake.NewWorkspaceBuilder(t, db).Seed(database.Workspace{
|
||||
r := dbfake.Workspace(t, db).Seed(database.Workspace{
|
||||
OrganizationID: user.OrganizationID,
|
||||
OwnerID: user.UserID,
|
||||
}).WithAgent().Do()
|
||||
@ -322,7 +322,7 @@ func TestWorkspaceAgentListen(t *testing.T) {
|
||||
|
||||
client, db := coderdtest.NewWithDatabase(t, nil)
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
r := dbfake.NewWorkspaceBuilder(t, db).Seed(database.Workspace{
|
||||
r := dbfake.Workspace(t, db).Seed(database.Workspace{
|
||||
OrganizationID: user.OrganizationID,
|
||||
OwnerID: user.UserID,
|
||||
}).WithAgent().Do()
|
||||
@ -408,7 +408,7 @@ func TestWorkspaceAgentTailnet(t *testing.T) {
|
||||
client, db := coderdtest.NewWithDatabase(t, nil)
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
|
||||
r := dbfake.NewWorkspaceBuilder(t, db).Seed(database.Workspace{
|
||||
r := dbfake.Workspace(t, db).Seed(database.Workspace{
|
||||
OrganizationID: user.OrganizationID,
|
||||
OwnerID: user.UserID,
|
||||
}).WithAgent().Do()
|
||||
@ -454,7 +454,7 @@ func TestWorkspaceAgentTailnetDirectDisabled(t *testing.T) {
|
||||
DeploymentValues: dv,
|
||||
})
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
r := dbfake.NewWorkspaceBuilder(t, db).Seed(database.Workspace{
|
||||
r := dbfake.Workspace(t, db).Seed(database.Workspace{
|
||||
OrganizationID: user.OrganizationID,
|
||||
OwnerID: user.UserID,
|
||||
}).WithAgent().Do()
|
||||
@ -517,7 +517,7 @@ func TestWorkspaceAgentListeningPorts(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
r := dbfake.NewWorkspaceBuilder(t, db).Seed(database.Workspace{
|
||||
r := dbfake.Workspace(t, db).Seed(database.Workspace{
|
||||
OrganizationID: user.OrganizationID,
|
||||
OwnerID: user.UserID,
|
||||
}).WithAgent(func(agents []*proto.Agent) []*proto.Agent {
|
||||
@ -752,7 +752,7 @@ func TestWorkspaceAgentAppHealth(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
r := dbfake.NewWorkspaceBuilder(t, db).Seed(database.Workspace{
|
||||
r := dbfake.Workspace(t, db).Seed(database.Workspace{
|
||||
OrganizationID: user.OrganizationID,
|
||||
OwnerID: user.UserID,
|
||||
}).WithAgent(func(agents []*proto.Agent) []*proto.Agent {
|
||||
@ -819,7 +819,7 @@ func TestWorkspaceAgentReportStats(t *testing.T) {
|
||||
|
||||
client, db := coderdtest.NewWithDatabase(t, nil)
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
r := dbfake.NewWorkspaceBuilder(t, db).Seed(database.Workspace{
|
||||
r := dbfake.Workspace(t, db).Seed(database.Workspace{
|
||||
OrganizationID: user.OrganizationID,
|
||||
OwnerID: user.UserID,
|
||||
}).WithAgent().Do()
|
||||
@ -886,7 +886,7 @@ func TestWorkspaceAgent_LifecycleState(t *testing.T) {
|
||||
|
||||
client, db := coderdtest.NewWithDatabase(t, nil)
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
r := dbfake.NewWorkspaceBuilder(t, db).Seed(database.Workspace{
|
||||
r := dbfake.Workspace(t, db).Seed(database.Workspace{
|
||||
OrganizationID: user.OrganizationID,
|
||||
OwnerID: user.UserID,
|
||||
}).WithAgent().Do()
|
||||
@ -951,7 +951,7 @@ func TestWorkspaceAgent_Metadata(t *testing.T) {
|
||||
|
||||
client, db := coderdtest.NewWithDatabase(t, nil)
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
r := dbfake.NewWorkspaceBuilder(t, db).Seed(database.Workspace{
|
||||
r := dbfake.Workspace(t, db).Seed(database.Workspace{
|
||||
OrganizationID: user.OrganizationID,
|
||||
OwnerID: user.UserID,
|
||||
}).WithAgent(func(agents []*proto.Agent) []*proto.Agent {
|
||||
@ -1129,7 +1129,7 @@ func TestWorkspaceAgent_Metadata_CatchMemoryLeak(t *testing.T) {
|
||||
Logger: &logger,
|
||||
})
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
r := dbfake.NewWorkspaceBuilder(t, db).Seed(database.Workspace{
|
||||
r := dbfake.Workspace(t, db).Seed(database.Workspace{
|
||||
OrganizationID: user.OrganizationID,
|
||||
OwnerID: user.UserID,
|
||||
}).WithAgent(func(agents []*proto.Agent) []*proto.Agent {
|
||||
@ -1258,7 +1258,7 @@ func TestWorkspaceAgent_Startup(t *testing.T) {
|
||||
|
||||
client, db := coderdtest.NewWithDatabase(t, nil)
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
r := dbfake.NewWorkspaceBuilder(t, db).Seed(database.Workspace{
|
||||
r := dbfake.Workspace(t, db).Seed(database.Workspace{
|
||||
OrganizationID: user.OrganizationID,
|
||||
OwnerID: user.UserID,
|
||||
}).WithAgent().Do()
|
||||
@ -1304,7 +1304,7 @@ func TestWorkspaceAgent_Startup(t *testing.T) {
|
||||
|
||||
client, db := coderdtest.NewWithDatabase(t, nil)
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
r := dbfake.NewWorkspaceBuilder(t, db).Seed(database.Workspace{
|
||||
r := dbfake.Workspace(t, db).Seed(database.Workspace{
|
||||
OrganizationID: user.OrganizationID,
|
||||
OwnerID: user.UserID,
|
||||
}).WithAgent().Do()
|
||||
@ -1352,7 +1352,7 @@ func TestWorkspaceAgent_UpdatedDERP(t *testing.T) {
|
||||
api.DERPMapper.Store(&derpMapFn)
|
||||
|
||||
// Start workspace a workspace agent.
|
||||
r := dbfake.NewWorkspaceBuilder(t, api.Database).Seed(database.Workspace{
|
||||
r := dbfake.Workspace(t, api.Database).Seed(database.Workspace{
|
||||
OrganizationID: user.OrganizationID,
|
||||
OwnerID: user.UserID,
|
||||
}).WithAgent().Do()
|
||||
|
Reference in New Issue
Block a user