mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
feat: add default autostart and ttl for new workspaces (#1632)
* database: add autostart_schedule and ttl to InsertWorkspace; make gen * coderd: workspaces: consume additional fields of CreateWorkspaceRequest * cli: update: add support for TTL and autostart_schedule * cli: create: add unit tests * coder: import `time/tzdata` for embedded timezone database * autobuild: fix unit test that only runs with a real db
This commit is contained in:
@ -389,11 +389,19 @@ func AwaitWorkspaceAgents(t *testing.T, client *codersdk.Client, build uuid.UUID
|
||||
|
||||
// CreateWorkspace creates a workspace for the user and template provided.
|
||||
// A random name is generated for it.
|
||||
func CreateWorkspace(t *testing.T, client *codersdk.Client, organization uuid.UUID, templateID uuid.UUID) codersdk.Workspace {
|
||||
workspace, err := client.CreateWorkspace(context.Background(), organization, codersdk.CreateWorkspaceRequest{
|
||||
TemplateID: templateID,
|
||||
Name: randomUsername(),
|
||||
})
|
||||
// To customize the defaults, pass a mutator func.
|
||||
func CreateWorkspace(t *testing.T, client *codersdk.Client, organization uuid.UUID, templateID uuid.UUID, mutators ...func(*codersdk.CreateWorkspaceRequest)) codersdk.Workspace {
|
||||
t.Helper()
|
||||
req := codersdk.CreateWorkspaceRequest{
|
||||
TemplateID: templateID,
|
||||
Name: randomUsername(),
|
||||
AutostartSchedule: ptr("CRON_TZ=US/Central * * * * *"),
|
||||
TTL: ptr(8 * time.Hour),
|
||||
}
|
||||
for _, mutator := range mutators {
|
||||
mutator(&req)
|
||||
}
|
||||
workspace, err := client.CreateWorkspace(context.Background(), organization, req)
|
||||
require.NoError(t, err)
|
||||
return workspace
|
||||
}
|
||||
@ -590,3 +598,7 @@ type roundTripper func(req *http.Request) (*http.Response, error)
|
||||
func (r roundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
return r(req)
|
||||
}
|
||||
|
||||
func ptr[T any](x T) *T {
|
||||
return &x
|
||||
}
|
||||
|
Reference in New Issue
Block a user