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

Function TestCreate

cli/create_test.go:330–727  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

328}
329
330func TestCreate(t *testing.T) {
331 t.Parallel()
332 t.Run("Create", func(t *testing.T) {
333 t.Parallel()
334 client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
335 owner := coderdtest.CreateFirstUser(t, client)
336 member, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID)
337 version := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, completeWithAgent())
338 coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
339 template := coderdtest.CreateTemplate(t, client, owner.OrganizationID, version.ID)
340 args := []string{
341 "create",
342 "my-workspace",
343 "--template", template.Name,
344 "--start-at", "9:30AM Mon-Fri US/Central",
345 "--stop-after", "8h",
346 "--automatic-updates", "always",
347 }
348 inv, root := clitest.New(t, args...)
349 clitest.SetupConfig(t, member, root)
350 doneChan := make(chan struct{})
351 pty := ptytest.New(t).Attach(inv)
352 go func() {
353 defer close(doneChan)
354 err := inv.Run()
355 assert.NoError(t, err)
356 }()
357 matches := []struct {
358 match string
359 write string
360 }{
361 {match: "compute.main"},
362 {match: "smith (linux, i386)"},
363 {match: "Confirm create", write: "yes"},
364 }
365 for _, m := range matches {
366 pty.ExpectMatch(m.match)
367 if len(m.write) > 0 {
368 pty.WriteLine(m.write)
369 }
370 }
371 <-doneChan
372
373 ws, err := member.WorkspaceByOwnerAndName(context.Background(), codersdk.Me, "my-workspace", codersdk.WorkspaceOptions{})
374 if assert.NoError(t, err, "expected workspace to be created") {
375 assert.Equal(t, ws.TemplateName, template.Name)
376 if assert.NotNil(t, ws.AutostartSchedule) {
377 assert.Equal(t, *ws.AutostartSchedule, "CRON_TZ=US/Central 30 9 * * Mon-Fri")
378 }
379 if assert.NotNil(t, ws.TTLMillis) {
380 assert.Equal(t, *ws.TTLMillis, 8*time.Hour.Milliseconds())
381 }
382 assert.Equal(t, codersdk.AutomaticUpdatesAlways, ws.AutomaticUpdates)
383 }
384 })
385
386 t.Run("CreateForOtherUser", func(t *testing.T) {
387 t.Parallel()

Callers

nothing calls this directly

Calls 15

NewFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
CreateTemplateVersionFunction · 0.92
CreateTemplateFunction · 0.92
NewFunction · 0.92
SetupConfigFunction · 0.92
NewFunction · 0.92
StartWithWaiterFunction · 0.92
ContextFunction · 0.92
TryReceiveFunction · 0.92

Tested by

no test coverage detected