-
Notifications
You must be signed in to change notification settings - Fork 887
chore: remove dbfake.WorkspaceBuild in favor of builder pattern #10814
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,15 +59,15 @@ func WorkspaceWithAgent( | |
agents = m(agents) | ||
} | ||
ws := Workspace(t, db, seed) | ||
WorkspaceBuild(t, db, ws, database.WorkspaceBuild{}, &sdkproto.Resource{ | ||
NewWorkspaceBuildBuilder(t, db, ws).Resource(&sdkproto.Resource{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I considered the same, then I wondered what we would call a "Builder" for a workspace, if we ever need one.. 😅 Edit: On second thought, perhaps you were suggesting something a bit different. Would you have one "Builder" for both workspace and workspacebuilds? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The pattern I'm planning to follow is I'd eventually like to convert everything in |
||
Name: "example", | ||
Type: "aws_instance", | ||
Agents: agents, | ||
}) | ||
}).Do() | ||
return ws, authToken | ||
} | ||
|
||
type BuildBuilder struct { | ||
type WorkspaceBuildBuilder struct { | ||
t testing.TB | ||
db database.Store | ||
ps pubsub.Pubsub | ||
|
@@ -76,29 +76,29 @@ type BuildBuilder struct { | |
resources []*sdkproto.Resource | ||
} | ||
|
||
func WorkspaceBuildBuilder(t testing.TB, db database.Store, ws database.Workspace) BuildBuilder { | ||
return BuildBuilder{t: t, db: db, ws: ws} | ||
func NewWorkspaceBuildBuilder(t testing.TB, db database.Store, ws database.Workspace) WorkspaceBuildBuilder { | ||
return WorkspaceBuildBuilder{t: t, db: db, ws: ws} | ||
} | ||
|
||
func (b BuildBuilder) Pubsub(ps pubsub.Pubsub) BuildBuilder { | ||
func (b WorkspaceBuildBuilder) Pubsub(ps pubsub.Pubsub) WorkspaceBuildBuilder { | ||
//nolint: revive // returns modified struct | ||
b.ps = ps | ||
return b | ||
} | ||
|
||
func (b BuildBuilder) Seed(seed database.WorkspaceBuild) BuildBuilder { | ||
func (b WorkspaceBuildBuilder) Seed(seed database.WorkspaceBuild) WorkspaceBuildBuilder { | ||
//nolint: revive // returns modified struct | ||
b.seed = seed | ||
return b | ||
} | ||
|
||
func (b BuildBuilder) Resource(resource *sdkproto.Resource) BuildBuilder { | ||
func (b WorkspaceBuildBuilder) Resource(resource ...*sdkproto.Resource) WorkspaceBuildBuilder { | ||
//nolint: revive // returns modified struct | ||
b.resources = append(b.resources, resource) | ||
b.resources = append(b.resources, resource...) | ||
return b | ||
} | ||
|
||
func (b BuildBuilder) Do() database.WorkspaceBuild { | ||
func (b WorkspaceBuildBuilder) Do() database.WorkspaceBuild { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. out of curiosity: wasn't that always There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's usually |
||
b.t.Helper() | ||
jobID := uuid.New() | ||
b.seed.ID = uuid.New() | ||
|
@@ -177,15 +177,6 @@ func (b BuildBuilder) Do() database.WorkspaceBuild { | |
return build | ||
} | ||
|
||
// WorkspaceBuild inserts a build and a successful job into the database. | ||
func WorkspaceBuild(t testing.TB, db database.Store, ws database.Workspace, seed database.WorkspaceBuild, resources ...*sdkproto.Resource) database.WorkspaceBuild { | ||
b := WorkspaceBuildBuilder(t, db, ws).Seed(seed) | ||
for _, r := range resources { | ||
b = b.Resource(r) | ||
} | ||
return b.Do() | ||
} | ||
|
||
// ProvisionerJobResources inserts a series of resources into a provisioner job. | ||
func ProvisionerJobResources(t testing.TB, db database.Store, job uuid.UUID, transition database.WorkspaceTransition, resources ...*sdkproto.Resource) { | ||
t.Helper() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor suggestion, perhaps we could rename this
s/Do/Build
, since a Builder Build's. I mean, the BuildBuilder is a bit unfortunate 😅, so I know, right, suggesting to add one more. But typically this naming goesDo
erDo()
,Build
erBuild()
, etc.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I wanted to avoid
Build()
as it might be confusing with WorkspaceBuild.Eventually I want the whole package to use the builder pattern and we can drop
Builder
from the function names. So you be like