MCPcopy Index your code
hub / github.com/coder/coder / prepareTestData

Function prepareTestData

cli/clitest/golden.go:249–301  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

247}
248
249func prepareTestData(t *testing.T) (*codersdk.Client, map[string]string) {
250 t.Helper()
251
252 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
253 defer cancel()
254
255 // This needs to be a fixed timezone because timezones increase the length
256 // of timestamp strings. The increased length can pad table formatting's
257 // and differ the table header spacings.
258 //nolint:gocritic
259 db, pubsub := dbtestutil.NewDB(t, dbtestutil.WithTimezone("UTC"))
260 rootClient := coderdtest.New(t, &coderdtest.Options{
261 Database: db,
262 Pubsub: pubsub,
263 IncludeProvisionerDaemon: true,
264 })
265 firstUser := coderdtest.CreateFirstUser(t, rootClient)
266 secondUser, err := rootClient.CreateUserWithOrgs(ctx, codersdk.CreateUserRequestWithOrgs{
267 Email: "testuser2@coder.com",
268 Username: "testuser2",
269 Password: coderdtest.FirstUserParams.Password,
270 OrganizationIDs: []uuid.UUID{firstUser.OrganizationID},
271 })
272 require.NoError(t, err)
273 version := coderdtest.CreateTemplateVersion(t, rootClient, firstUser.OrganizationID, nil)
274 version = coderdtest.AwaitTemplateVersionJobCompleted(t, rootClient, version.ID)
275 template := coderdtest.CreateTemplate(t, rootClient, firstUser.OrganizationID, version.ID, func(req *codersdk.CreateTemplateRequest) {
276 req.Name = "test-template"
277 })
278 workspace := coderdtest.CreateWorkspace(t, rootClient, template.ID, func(req *codersdk.CreateWorkspaceRequest) {
279 req.Name = "test-workspace"
280 })
281 workspaceBuild := coderdtest.AwaitWorkspaceBuildJobCompleted(t, rootClient, workspace.LatestBuild.ID)
282
283 replacements := map[string]string{
284 firstUser.UserID.String(): pad("[first user ID]", 36),
285 secondUser.ID.String(): pad("[second user ID]", 36),
286 firstUser.OrganizationID.String(): pad("[first org ID]", 36),
287 version.ID.String(): pad("[version ID]", 36),
288 version.Name: pad("[version name]", 36),
289 version.Job.ID.String(): pad("[version job ID]", 36),
290 version.Job.FileID.String(): pad("[version file ID]", 36),
291 version.Job.WorkerID.String(): pad("[version worker ID]", 36),
292 template.ID.String(): pad("[template ID]", 36),
293 workspace.ID.String(): pad("[workspace ID]", 36),
294 workspaceBuild.ID.String(): pad("[workspace build ID]", 36),
295 workspaceBuild.Job.ID.String(): pad("[workspace build job ID]", 36),
296 workspaceBuild.Job.FileID.String(): pad("[workspace build file ID]", 36),
297 workspaceBuild.Job.WorkerID.String(): pad("[workspace build worker ID]", 36),
298 }
299
300 return rootClient, replacements
301}
302
303func pad(s string, n int) string {
304 if len(s) >= n {

Callers 1

TestCommandHelpFunction · 0.85

Calls 13

NewDBFunction · 0.92
WithTimezoneFunction · 0.92
NewFunction · 0.92
CreateFirstUserFunction · 0.92
CreateTemplateVersionFunction · 0.92
CreateTemplateFunction · 0.92
CreateWorkspaceFunction · 0.92
CreateUserWithOrgsMethod · 0.80
padFunction · 0.70
HelperMethod · 0.65

Tested by 1

TestCommandHelpFunction · 0.68