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

Function TestShow

cli/show_test.go:22–121  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

20)
21
22func TestShow(t *testing.T) {
23 t.Parallel()
24 t.Run("Exists", func(t *testing.T) {
25 t.Parallel()
26 client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
27 owner := coderdtest.CreateFirstUser(t, client)
28 member, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID)
29 version := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, completeWithAgent())
30 coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
31 template := coderdtest.CreateTemplate(t, client, owner.OrganizationID, version.ID)
32 workspace := coderdtest.CreateWorkspace(t, member, template.ID)
33 build := coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspace.LatestBuild.ID)
34
35 args := []string{
36 "show",
37 workspace.Name,
38 }
39 inv, root := clitest.New(t, args...)
40 clitest.SetupConfig(t, member, root)
41 doneChan := make(chan struct{})
42 pty := ptytest.New(t).Attach(inv)
43 ctx := testutil.Context(t, testutil.WaitShort)
44 go func() {
45 defer close(doneChan)
46 err := inv.WithContext(ctx).Run()
47 assert.NoError(t, err)
48 }()
49 matches := []struct {
50 match string
51 write string
52 }{
53 {match: fmt.Sprintf("%s/%s", workspace.OwnerName, workspace.Name)},
54 {match: fmt.Sprintf("(%s since ", build.Status)},
55 {match: fmt.Sprintf("%s:%s", workspace.TemplateName, workspace.LatestBuild.TemplateVersionName)},
56 {match: "compute.main"},
57 {match: "smith (linux, i386)"},
58 {match: "coder ssh " + workspace.Name},
59 }
60 for _, m := range matches {
61 pty.ExpectMatchContext(ctx, m.match)
62 if len(m.write) > 0 {
63 pty.WriteLine(m.write)
64 }
65 }
66 _ = testutil.TryReceive(ctx, t, doneChan)
67 })
68
69 // Regression test: workspace names that are valid dashless UUIDs
70 // (32 hex chars) should be looked up by name, not parsed as a
71 // UUID and fetched by ID (which 404s).
72 t.Run("WorkspaceWithUUIDLikeName", func(t *testing.T) {
73 t.Parallel()
74 client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
75 owner := coderdtest.CreateFirstUser(t, client)
76 member, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID)
77 version := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, completeWithAgent())
78 coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
79 template := coderdtest.CreateTemplate(t, client, owner.OrganizationID, version.ID)

Callers

nothing calls this directly

Calls 15

NewFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
CreateTemplateVersionFunction · 0.92
CreateTemplateFunction · 0.92
CreateWorkspaceFunction · 0.92
NewFunction · 0.92
SetupConfigFunction · 0.92
NewFunction · 0.92
ContextFunction · 0.92

Tested by

no test coverage detected