Skip to content

chore: remove dbfake.Workspace #10880

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
chore: remove dbfake.Workspace
  • Loading branch information
spikecurtis committed Nov 27, 2023
commit eb0922cd4e8ffff8a832341d903b74dfdad14ecc
55 changes: 19 additions & 36 deletions cli/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,12 @@ func TestWorkspaceAgent(t *testing.T) {
AzureCertificates: certificates,
})
user := coderdtest.CreateFirstUser(t, client)
ws := dbfake.Workspace(t, db, database.Workspace{
r := dbfake.NewWorkspaceBuilder(t, db).Seed(database.Workspace{
OrganizationID: user.OrganizationID,
OwnerID: user.UserID,
})
dbfake.NewWorkspaceBuildBuilder(t, db, ws).Resource(&proto.Resource{
Name: "somename",
Type: "someinstance",
Agents: []*proto.Agent{{
Auth: &proto.Agent_InstanceId{
InstanceId: instanceID,
},
}},
}).WithAgent(func(agents []*proto.Agent) []*proto.Agent {
agents[0].Auth = &proto.Agent_InstanceId{InstanceId: instanceID}
return agents
}).Do()

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

ctx := inv.Context()
clitest.Start(t, inv)
coderdtest.AwaitWorkspaceAgents(t, client, ws.ID)
workspace, err := client.Workspace(ctx, ws.ID)
coderdtest.AwaitWorkspaceAgents(t, client, r.Workspace.ID)
workspace, err := client.Workspace(ctx, r.Workspace.ID)
require.NoError(t, err)
resources := workspace.LatestBuild.Resources
if assert.NotEmpty(t, workspace.LatestBuild.Resources) && assert.NotEmpty(t, resources[0].Agents) {
Expand All @@ -111,18 +105,12 @@ func TestWorkspaceAgent(t *testing.T) {
AWSCertificates: certificates,
})
user := coderdtest.CreateFirstUser(t, client)
ws := dbfake.Workspace(t, db, database.Workspace{
r := dbfake.NewWorkspaceBuilder(t, db).Seed(database.Workspace{
OrganizationID: user.OrganizationID,
OwnerID: user.UserID,
})
dbfake.NewWorkspaceBuildBuilder(t, db, ws).Resource(&proto.Resource{
Name: "somename",
Type: "someinstance",
Agents: []*proto.Agent{{
Auth: &proto.Agent_InstanceId{
InstanceId: instanceID,
},
}},
}).WithAgent(func(agents []*proto.Agent) []*proto.Agent {
agents[0].Auth = &proto.Agent_InstanceId{InstanceId: instanceID}
return agents
}).Do()

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

clitest.Start(t, inv)
ctx := inv.Context()
coderdtest.AwaitWorkspaceAgents(t, client, ws.ID)
workspace, err := client.Workspace(ctx, ws.ID)
coderdtest.AwaitWorkspaceAgents(t, client, r.Workspace.ID)
workspace, err := client.Workspace(ctx, r.Workspace.ID)
require.NoError(t, err)
resources := workspace.LatestBuild.Resources
if assert.NotEmpty(t, resources) && assert.NotEmpty(t, resources[0].Agents) {
Expand All @@ -155,19 +143,14 @@ func TestWorkspaceAgent(t *testing.T) {
})
owner := coderdtest.CreateFirstUser(t, client)
member, memberUser := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID)
ws := dbfake.Workspace(t, db, database.Workspace{
r := dbfake.NewWorkspaceBuilder(t, db).Seed(database.Workspace{
OrganizationID: owner.OrganizationID,
OwnerID: memberUser.ID,
})
dbfake.NewWorkspaceBuildBuilder(t, db, ws).Resource(&proto.Resource{
Name: "somename",
Type: "someinstance",
Agents: []*proto.Agent{{
Auth: &proto.Agent_InstanceId{
InstanceId: instanceID,
},
}},
}).WithAgent(func(agents []*proto.Agent) []*proto.Agent {
agents[0].Auth = &proto.Agent_InstanceId{InstanceId: instanceID}
return agents
}).Do()

inv, cfg := clitest.New(t, "agent", "--auth", "google-instance-identity", "--agent-url", client.URL.String())
clitest.SetupConfig(t, member, cfg)

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

ctx := inv.Context()
coderdtest.AwaitWorkspaceAgents(t, client, ws.ID)
workspace, err := client.Workspace(ctx, ws.ID)
coderdtest.AwaitWorkspaceAgents(t, client, r.Workspace.ID)
workspace, err := client.Workspace(ctx, r.Workspace.ID)
require.NoError(t, err)
resources := workspace.LatestBuild.Resources
if assert.NotEmpty(t, resources) && assert.NotEmpty(t, resources[0].Agents) {
Expand Down
8 changes: 4 additions & 4 deletions cli/configssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,11 +695,11 @@ func TestConfigSSH_Hostnames(t *testing.T) {
owner := coderdtest.CreateFirstUser(t, client)
member, memberUser := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID)

ws := dbfake.Workspace(t, db, database.Workspace{
r := dbfake.NewWorkspaceBuilder(t, db).Seed(database.Workspace{
OrganizationID: owner.OrganizationID,
OwnerID: memberUser.ID,
})
dbfake.NewWorkspaceBuildBuilder(t, db, ws).Resource(resources...).Do()
}).Do()
dbfake.NewWorkspaceBuildBuilder(t, db, r.Workspace).Resource(resources...).Do()
sshConfigFile := sshConfigFileName(t)

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

var expectedHosts []string
for _, hostnamePattern := range tt.expected {
hostname := strings.ReplaceAll(hostnamePattern, "@", ws.Name)
hostname := strings.ReplaceAll(hostnamePattern, "@", r.Workspace.Name)
expectedHosts = append(expectedHosts, hostname)
}

Expand Down
7 changes: 0 additions & 7 deletions coderd/database/dbfake/dbfake.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,6 @@ func (b WorkspaceBuilder) Do() WorkspaceResponse {
return r
}

// Workspace inserts a workspace into the database.
func Workspace(t testing.TB, db database.Store, seed database.Workspace) database.Workspace {
t.Helper()
r := NewWorkspaceBuilder(t, db).Seed(seed).Do()
return r.Workspace
}

type WorkspaceBuildBuilder struct {
t testing.TB
db database.Store
Expand Down
Loading