Skip to content

chore: add Resources() to dbfake.WorkspaceBuilder #10883

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

Closed
wants to merge 1 commit into from
Closed
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: add Resources() to dbfake.WorkspaceBuilder
  • Loading branch information
spikecurtis committed Nov 29, 2023
commit bd9cf1256e9ad836b7c6f757764565d5d4762539
11 changes: 6 additions & 5 deletions cli/configssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,11 +695,12 @@ func TestConfigSSH_Hostnames(t *testing.T) {
owner := coderdtest.CreateFirstUser(t, client)
member, memberUser := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID)

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

inv, root := clitest.New(t, "config-ssh", "--ssh-config-file", sshConfigFile)
Expand Down
8 changes: 8 additions & 0 deletions coderd/database/dbfake/dbfake.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ func (b WorkspaceBuilder) WithAgent(mutations ...func([]*sdkproto.Agent) []*sdkp
return b
}

func (b WorkspaceBuilder) Resource(resource ...*sdkproto.Resource) WorkspaceBuilder {
//nolint: revive // returns modified struct
b.resources = append(b.resources, resource...)
return b
}

func (b WorkspaceBuilder) Do() WorkspaceResponse {
var r WorkspaceResponse
// This intentionally fulfills the minimum requirements of the schema.
Expand All @@ -82,6 +88,8 @@ func (b WorkspaceBuilder) Do() WorkspaceResponse {
r.Workspace = dbgen.Workspace(b.t, b.db, b.seed)
if b.agentToken != "" {
r.AgentToken = b.agentToken
}
if len(b.resources) > 0 {
r.Build = WorkspaceBuild(b.t, b.db, r.Workspace).
Resource(b.resources...).
Do()
Expand Down