CreateWorkspace creates a workspace for the user and template provided. A random name is generated for it. To customize the defaults, pass a mutator func.
(t testing.TB, client *codersdk.Client, templateID uuid.UUID, mutators ...func(*codersdk.CreateWorkspaceRequest))
| 1443 | // A random name is generated for it. |
| 1444 | // To customize the defaults, pass a mutator func. |
| 1445 | func CreateWorkspace(t testing.TB, client *codersdk.Client, templateID uuid.UUID, mutators ...func(*codersdk.CreateWorkspaceRequest)) codersdk.Workspace { |
| 1446 | t.Helper() |
| 1447 | req := codersdk.CreateWorkspaceRequest{ |
| 1448 | TemplateID: templateID, |
| 1449 | Name: RandomUsername(t), |
| 1450 | AutostartSchedule: ptr.Ref("CRON_TZ=US/Central 30 9 * * 1-5"), |
| 1451 | TTLMillis: ptr.Ref((8 * time.Hour).Milliseconds()), |
| 1452 | AutomaticUpdates: codersdk.AutomaticUpdatesNever, |
| 1453 | } |
| 1454 | for _, mutator := range mutators { |
| 1455 | mutator(&req) |
| 1456 | } |
| 1457 | workspace, err := client.CreateUserWorkspace(context.Background(), codersdk.Me, req) |
| 1458 | require.NoError(t, err) |
| 1459 | return workspace |
| 1460 | } |
| 1461 | |
| 1462 | // TransitionWorkspace is a convenience method for transitioning a workspace from one state to another. |
| 1463 | func MustTransitionWorkspace(t testing.TB, client *codersdk.Client, workspaceID uuid.UUID, from, to codersdk.WorkspaceTransition, muts ...func(req *codersdk.CreateWorkspaceBuildRequest)) codersdk.Workspace { |