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

Function TestList

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

Source from the content-addressed store, hash-verified

20)
21
22func TestList(t *testing.T) {
23 t.Parallel()
24 t.Run("Single", func(t *testing.T) {
25 t.Parallel()
26 client, db := coderdtest.NewWithDatabase(t, nil)
27 owner := coderdtest.CreateFirstUser(t, client)
28 member, memberUser := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID)
29 // setup template
30 r := dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{
31 OrganizationID: owner.OrganizationID,
32 OwnerID: memberUser.ID,
33 }).WithAgent().Do()
34
35 inv, root := clitest.New(t, "ls")
36 clitest.SetupConfig(t, member, root)
37 pty := ptytest.New(t).Attach(inv)
38
39 ctx, cancelFunc := context.WithTimeout(context.Background(), testutil.WaitLong)
40 defer cancelFunc()
41 done := make(chan any)
42 go func() {
43 errC := inv.WithContext(ctx).Run()
44 assert.NoError(t, errC)
45 close(done)
46 }()
47 pty.ExpectMatch(r.Workspace.Name)
48 pty.ExpectMatch("Started")
49 cancelFunc()
50 <-done
51 })
52
53 t.Run("JSON", func(t *testing.T) {
54 t.Parallel()
55 client, db := coderdtest.NewWithDatabase(t, nil)
56 owner := coderdtest.CreateFirstUser(t, client)
57 member, memberUser := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID)
58 _ = dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{
59 OrganizationID: owner.OrganizationID,
60 OwnerID: memberUser.ID,
61 }).WithAgent().Do()
62
63 inv, root := clitest.New(t, "list", "--output=json")
64 clitest.SetupConfig(t, member, root)
65
66 ctx, cancelFunc := context.WithTimeout(context.Background(), testutil.WaitLong)
67 defer cancelFunc()
68
69 out := bytes.NewBuffer(nil)
70 inv.Stdout = out
71 err := inv.WithContext(ctx).Run()
72 require.NoError(t, err)
73
74 var workspaces []codersdk.Workspace
75 require.NoError(t, json.Unmarshal(out.Bytes(), &workspaces))
76 require.Len(t, workspaces, 1)
77 })
78
79 t.Run("NoWorkspacesJSON", func(t *testing.T) {

Callers

nothing calls this directly

Calls 15

NewWithDatabaseFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
WorkspaceBuildFunction · 0.92
NewFunction · 0.92
SetupConfigFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
ScopedRoleOrgAuditorFunction · 0.92
ContextFunction · 0.92
WithAgentMethod · 0.80
WithContextMethod · 0.80

Tested by

no test coverage detected