MCPcopy Create free account
hub / github.com/coder/coder / setupDeps

Function setupDeps

coderd/workspacestats/batcher_internal_test.go:171–219  ·  view source on GitHub ↗

setupDeps sets up a set of test dependencies. It creates an organization, user, template, workspace, and agent along with all the other miscellaneous plumbing required to link them together.

(t *testing.T, store database.Store, ps pubsub.Pubsub)

Source from the content-addressed store, hash-verified

169// along with all the other miscellaneous plumbing required to link
170// them together.
171func setupDeps(t *testing.T, store database.Store, ps pubsub.Pubsub) deps {
172 t.Helper()
173
174 org := dbgen.Organization(t, store, database.Organization{})
175 user := dbgen.User(t, store, database.User{})
176 _, err := store.InsertOrganizationMember(context.Background(), database.InsertOrganizationMemberParams{
177 OrganizationID: org.ID,
178 UserID: user.ID,
179 Roles: []string{codersdk.RoleOrganizationMember},
180 })
181 require.NoError(t, err)
182 tv := dbgen.TemplateVersion(t, store, database.TemplateVersion{
183 OrganizationID: org.ID,
184 CreatedBy: user.ID,
185 })
186 tpl := dbgen.Template(t, store, database.Template{
187 CreatedBy: user.ID,
188 OrganizationID: org.ID,
189 ActiveVersionID: tv.ID,
190 })
191 ws := dbgen.Workspace(t, store, database.WorkspaceTable{
192 TemplateID: tpl.ID,
193 OwnerID: user.ID,
194 OrganizationID: org.ID,
195 LastUsedAt: time.Now().Add(-time.Hour),
196 })
197 pj := dbgen.ProvisionerJob(t, store, ps, database.ProvisionerJob{
198 InitiatorID: user.ID,
199 OrganizationID: org.ID,
200 })
201 _ = dbgen.WorkspaceBuild(t, store, database.WorkspaceBuild{
202 TemplateVersionID: tv.ID,
203 WorkspaceID: ws.ID,
204 JobID: pj.ID,
205 })
206 res := dbgen.WorkspaceResource(t, store, database.WorkspaceResource{
207 Transition: database.WorkspaceTransitionStart,
208 JobID: pj.ID,
209 })
210 agt := dbgen.WorkspaceAgent(t, store, database.WorkspaceAgent{
211 ResourceID: res.ID,
212 })
213 return deps{
214 Agent: agt,
215 Template: tpl,
216 User: user,
217 Workspace: ws,
218 }
219}
220
221// mustRandInt64n returns a random int64 in the range [0, n).
222func mustRandInt64n(t *testing.T, n int64) int64 {

Callers 1

TestBatchStatsFunction · 0.85

Calls 12

OrganizationFunction · 0.92
UserFunction · 0.92
TemplateVersionFunction · 0.92
TemplateFunction · 0.92
WorkspaceFunction · 0.92
ProvisionerJobFunction · 0.92
WorkspaceBuildFunction · 0.92
WorkspaceResourceFunction · 0.92
WorkspaceAgentFunction · 0.92
HelperMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected