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)
| 169 | // along with all the other miscellaneous plumbing required to link |
| 170 | // them together. |
| 171 | func 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). |
| 222 | func mustRandInt64n(t *testing.T, n int64) int64 { |
no test coverage detected