Skip to content

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

Merged
merged 1 commit into from
Nov 22, 2023

Conversation

spikecurtis
Copy link
Contributor

I'd like to convert dbfake into a builder pattern to prevent a proliferation of XXXWithYYY methods. This is one step of the way by removing the Non-builder function.

Copy link
Contributor Author

@spikecurtis spikecurtis force-pushed the spike/db-fake-workspace-build branch from 24624dc to 70cc9f4 Compare November 21, 2023 11:06
Base automatically changed from spike/ssh-tests-dbfake to main November 21, 2023 12:22
@spikecurtis spikecurtis force-pushed the spike/db-fake-workspace-build branch from 70cc9f4 to c81a476 Compare November 21, 2023 12:28
Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactoring LGTM

return b
}

func (b BuildBuilder) Do() database.WorkspaceBuild {
func (b WorkspaceBuildBuilder) Do() database.WorkspaceBuild {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of curiosity: wasn't that always Build()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's usually Build() but I'm attempting to avoid a clash with WorkspaceBuild. I don't mind too much either way.

Name: "somename",
Type: "someinstance",
Agents: []*proto.Agent{{
Auth: &proto.Agent_InstanceId{
InstanceId: instanceID,
},
}},
})
}).Do()
Copy link
Member

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 goes Doer Do(), Builder Build(), etc.

Copy link
Contributor Author

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

r := dbfake.Workspace(t, db).Do()

@@ -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{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we do NewWorkspaceBuilder instead? Then the Build function would implicitly do what we expect as well.

Copy link
Member

@mafredri mafredri Nov 21, 2023

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pattern I'm planning to follow is NewXxxxxBuilder() for the function that creates a builder (where Xxxxx is the resource type), so NewWorkspaceBuildBuilder() is the builder for a WorkspaceBuild.

I'd eventually like to convert everything in dbfake to a builder pattern, and then I think we could potentially drop the Builder suffix and the New prefix for the sake of readability. But while I'm changing things over, it's useful to be able tell what is and isn't a builder.

@spikecurtis spikecurtis merged commit b25e5dc into main Nov 22, 2023
@spikecurtis spikecurtis deleted the spike/db-fake-workspace-build branch November 22, 2023 09:05
@github-actions github-actions bot locked and limited conversation to collaborators Nov 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants