Skip to content

Commit 4548ad7

Browse files
authored
chore: remove dbfake.Workspace (#10880)
Remove dbfake.Workspace and use builder instead.
1 parent 78283a7 commit 4548ad7

File tree

4 files changed

+114
-199
lines changed

4 files changed

+114
-199
lines changed

cli/agent_test.go

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,12 @@ func TestWorkspaceAgent(t *testing.T) {
6868
AzureCertificates: certificates,
6969
})
7070
user := coderdtest.CreateFirstUser(t, client)
71-
ws := dbfake.Workspace(t, db, database.Workspace{
71+
r := dbfake.NewWorkspaceBuilder(t, db).Seed(database.Workspace{
7272
OrganizationID: user.OrganizationID,
7373
OwnerID: user.UserID,
74-
})
75-
dbfake.NewWorkspaceBuildBuilder(t, db, ws).Resource(&proto.Resource{
76-
Name: "somename",
77-
Type: "someinstance",
78-
Agents: []*proto.Agent{{
79-
Auth: &proto.Agent_InstanceId{
80-
InstanceId: instanceID,
81-
},
82-
}},
74+
}).WithAgent(func(agents []*proto.Agent) []*proto.Agent {
75+
agents[0].Auth = &proto.Agent_InstanceId{InstanceId: instanceID}
76+
return agents
8377
}).Do()
8478

8579
inv, _ := clitest.New(t, "agent", "--auth", "azure-instance-identity", "--agent-url", client.URL.String())
@@ -90,8 +84,8 @@ func TestWorkspaceAgent(t *testing.T) {
9084

9185
ctx := inv.Context()
9286
clitest.Start(t, inv)
93-
coderdtest.AwaitWorkspaceAgents(t, client, ws.ID)
94-
workspace, err := client.Workspace(ctx, ws.ID)
87+
coderdtest.AwaitWorkspaceAgents(t, client, r.Workspace.ID)
88+
workspace, err := client.Workspace(ctx, r.Workspace.ID)
9589
require.NoError(t, err)
9690
resources := workspace.LatestBuild.Resources
9791
if assert.NotEmpty(t, workspace.LatestBuild.Resources) && assert.NotEmpty(t, resources[0].Agents) {
@@ -111,18 +105,12 @@ func TestWorkspaceAgent(t *testing.T) {
111105
AWSCertificates: certificates,
112106
})
113107
user := coderdtest.CreateFirstUser(t, client)
114-
ws := dbfake.Workspace(t, db, database.Workspace{
108+
r := dbfake.NewWorkspaceBuilder(t, db).Seed(database.Workspace{
115109
OrganizationID: user.OrganizationID,
116110
OwnerID: user.UserID,
117-
})
118-
dbfake.NewWorkspaceBuildBuilder(t, db, ws).Resource(&proto.Resource{
119-
Name: "somename",
120-
Type: "someinstance",
121-
Agents: []*proto.Agent{{
122-
Auth: &proto.Agent_InstanceId{
123-
InstanceId: instanceID,
124-
},
125-
}},
111+
}).WithAgent(func(agents []*proto.Agent) []*proto.Agent {
112+
agents[0].Auth = &proto.Agent_InstanceId{InstanceId: instanceID}
113+
return agents
126114
}).Do()
127115

128116
inv, _ := clitest.New(t, "agent", "--auth", "aws-instance-identity", "--agent-url", client.URL.String())
@@ -133,8 +121,8 @@ func TestWorkspaceAgent(t *testing.T) {
133121

134122
clitest.Start(t, inv)
135123
ctx := inv.Context()
136-
coderdtest.AwaitWorkspaceAgents(t, client, ws.ID)
137-
workspace, err := client.Workspace(ctx, ws.ID)
124+
coderdtest.AwaitWorkspaceAgents(t, client, r.Workspace.ID)
125+
workspace, err := client.Workspace(ctx, r.Workspace.ID)
138126
require.NoError(t, err)
139127
resources := workspace.LatestBuild.Resources
140128
if assert.NotEmpty(t, resources) && assert.NotEmpty(t, resources[0].Agents) {
@@ -155,19 +143,14 @@ func TestWorkspaceAgent(t *testing.T) {
155143
})
156144
owner := coderdtest.CreateFirstUser(t, client)
157145
member, memberUser := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID)
158-
ws := dbfake.Workspace(t, db, database.Workspace{
146+
r := dbfake.NewWorkspaceBuilder(t, db).Seed(database.Workspace{
159147
OrganizationID: owner.OrganizationID,
160148
OwnerID: memberUser.ID,
161-
})
162-
dbfake.NewWorkspaceBuildBuilder(t, db, ws).Resource(&proto.Resource{
163-
Name: "somename",
164-
Type: "someinstance",
165-
Agents: []*proto.Agent{{
166-
Auth: &proto.Agent_InstanceId{
167-
InstanceId: instanceID,
168-
},
169-
}},
149+
}).WithAgent(func(agents []*proto.Agent) []*proto.Agent {
150+
agents[0].Auth = &proto.Agent_InstanceId{InstanceId: instanceID}
151+
return agents
170152
}).Do()
153+
171154
inv, cfg := clitest.New(t, "agent", "--auth", "google-instance-identity", "--agent-url", client.URL.String())
172155
clitest.SetupConfig(t, member, cfg)
173156

@@ -179,8 +162,8 @@ func TestWorkspaceAgent(t *testing.T) {
179162
)
180163

181164
ctx := inv.Context()
182-
coderdtest.AwaitWorkspaceAgents(t, client, ws.ID)
183-
workspace, err := client.Workspace(ctx, ws.ID)
165+
coderdtest.AwaitWorkspaceAgents(t, client, r.Workspace.ID)
166+
workspace, err := client.Workspace(ctx, r.Workspace.ID)
184167
require.NoError(t, err)
185168
resources := workspace.LatestBuild.Resources
186169
if assert.NotEmpty(t, resources) && assert.NotEmpty(t, resources[0].Agents) {

cli/configssh_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -695,11 +695,11 @@ func TestConfigSSH_Hostnames(t *testing.T) {
695695
owner := coderdtest.CreateFirstUser(t, client)
696696
member, memberUser := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID)
697697

698-
ws := dbfake.Workspace(t, db, database.Workspace{
698+
r := dbfake.NewWorkspaceBuilder(t, db).Seed(database.Workspace{
699699
OrganizationID: owner.OrganizationID,
700700
OwnerID: memberUser.ID,
701-
})
702-
dbfake.NewWorkspaceBuildBuilder(t, db, ws).Resource(resources...).Do()
701+
}).Do()
702+
dbfake.NewWorkspaceBuildBuilder(t, db, r.Workspace).Resource(resources...).Do()
703703
sshConfigFile := sshConfigFileName(t)
704704

705705
inv, root := clitest.New(t, "config-ssh", "--ssh-config-file", sshConfigFile)
@@ -724,7 +724,7 @@ func TestConfigSSH_Hostnames(t *testing.T) {
724724

725725
var expectedHosts []string
726726
for _, hostnamePattern := range tt.expected {
727-
hostname := strings.ReplaceAll(hostnamePattern, "@", ws.Name)
727+
hostname := strings.ReplaceAll(hostnamePattern, "@", r.Workspace.Name)
728728
expectedHosts = append(expectedHosts, hostname)
729729
}
730730

coderd/database/dbfake/dbfake.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,6 @@ func (b WorkspaceBuilder) Do() WorkspaceResponse {
8989
return r
9090
}
9191

92-
// Workspace inserts a workspace into the database.
93-
func Workspace(t testing.TB, db database.Store, seed database.Workspace) database.Workspace {
94-
t.Helper()
95-
r := NewWorkspaceBuilder(t, db).Seed(seed).Do()
96-
return r.Workspace
97-
}
98-
9992
type WorkspaceBuildBuilder struct {
10093
t testing.TB
10194
db database.Store

0 commit comments

Comments
 (0)