mirror of
https://github.com/coder/coder.git
synced 2025-07-09 11:45:56 +00:00
chore: convert dbfake.ProvisionerJobResources to builder (#10881)
Convert to builder for consistency with rest of the package. This will make it easier to use, and means we can drop "Builder" from function arguments since they are all builders in the package.
This commit is contained in:
@ -187,11 +187,11 @@ func (b WorkspaceBuildBuilder) Do() database.WorkspaceBuild {
|
|||||||
Valid: true,
|
Valid: true,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
ProvisionerJobResources(b.t, b.db, jobID, b.seed.Transition, b.resources...)
|
NewProvisionerJobResourcesBuilder(b.t, b.db, jobID, b.seed.Transition, b.resources...).Do()
|
||||||
b.seed.TemplateVersionID = templateVersion.ID
|
b.seed.TemplateVersionID = templateVersion.ID
|
||||||
}
|
}
|
||||||
build := dbgen.WorkspaceBuild(b.t, b.db, b.seed)
|
build := dbgen.WorkspaceBuild(b.t, b.db, b.seed)
|
||||||
ProvisionerJobResources(b.t, b.db, job.ID, b.seed.Transition, b.resources...)
|
NewProvisionerJobResourcesBuilder(b.t, b.db, job.ID, b.seed.Transition, b.resources...).Do()
|
||||||
if b.ps != nil {
|
if b.ps != nil {
|
||||||
err = b.ps.Publish(codersdk.WorkspaceNotifyChannel(build.WorkspaceID), []byte{})
|
err = b.ps.Publish(codersdk.WorkspaceNotifyChannel(build.WorkspaceID), []byte{})
|
||||||
require.NoError(b.t, err)
|
require.NoError(b.t, err)
|
||||||
@ -199,16 +199,37 @@ func (b WorkspaceBuildBuilder) Do() database.WorkspaceBuild {
|
|||||||
return build
|
return build
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProvisionerJobResources inserts a series of resources into a provisioner job.
|
type ProvisionerJobResourcesBuilder struct {
|
||||||
func ProvisionerJobResources(t testing.TB, db database.Store, job uuid.UUID, transition database.WorkspaceTransition, resources ...*sdkproto.Resource) {
|
t testing.TB
|
||||||
t.Helper()
|
db database.Store
|
||||||
|
jobID uuid.UUID
|
||||||
|
transition database.WorkspaceTransition
|
||||||
|
resources []*sdkproto.Resource
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewProvisionerJobResourcesBuilder inserts a series of resources into a provisioner job.
|
||||||
|
func NewProvisionerJobResourcesBuilder(
|
||||||
|
t testing.TB, db database.Store, jobID uuid.UUID, transition database.WorkspaceTransition, resources ...*sdkproto.Resource,
|
||||||
|
) ProvisionerJobResourcesBuilder {
|
||||||
|
return ProvisionerJobResourcesBuilder{
|
||||||
|
t: t,
|
||||||
|
db: db,
|
||||||
|
jobID: jobID,
|
||||||
|
transition: transition,
|
||||||
|
resources: resources,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b ProvisionerJobResourcesBuilder) Do() {
|
||||||
|
b.t.Helper()
|
||||||
|
transition := b.transition
|
||||||
if transition == "" {
|
if transition == "" {
|
||||||
// Default to start!
|
// Default to start!
|
||||||
transition = database.WorkspaceTransitionStart
|
transition = database.WorkspaceTransitionStart
|
||||||
}
|
}
|
||||||
for _, resource := range resources {
|
for _, resource := range b.resources {
|
||||||
//nolint:gocritic // This is only used by tests.
|
//nolint:gocritic // This is only used by tests.
|
||||||
err := provisionerdserver.InsertWorkspaceResource(dbauthz.AsSystemRestricted(context.Background()), db, job, transition, resource, &telemetry.Snapshot{})
|
err := provisionerdserver.InsertWorkspaceResource(dbauthz.AsSystemRestricted(context.Background()), b.db, b.jobID, transition, resource, &telemetry.Snapshot{})
|
||||||
require.NoError(t, err)
|
require.NoError(b.t, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user