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

Function TestWorkspaceResources

cli/cliui/resources_test.go:15–113  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestWorkspaceResources(t *testing.T) {
16 t.Parallel()
17 t.Run("SingleAgentSSH", func(t *testing.T) {
18 t.Parallel()
19 ptty := ptytest.New(t)
20 done := make(chan struct{})
21 go func() {
22 err := cliui.WorkspaceResources(ptty.Output(), []codersdk.WorkspaceResource{{
23 Type: "google_compute_instance",
24 Name: "dev",
25 Transition: codersdk.WorkspaceTransitionStart,
26 Agents: []codersdk.WorkspaceAgent{{
27 Name: "dev",
28 Status: codersdk.WorkspaceAgentConnected,
29 LifecycleState: codersdk.WorkspaceAgentLifecycleCreated,
30 Architecture: "amd64",
31 OperatingSystem: "linux",
32 Health: codersdk.WorkspaceAgentHealth{Healthy: true},
33 }},
34 }}, cliui.WorkspaceResourcesOptions{
35 WorkspaceName: "example",
36 })
37 assert.NoError(t, err)
38 close(done)
39 }()
40 ptty.ExpectMatch("coder ssh example")
41 <-done
42 })
43
44 t.Run("MultipleStates", func(t *testing.T) {
45 t.Parallel()
46 ptty := ptytest.New(t)
47 disconnected := dbtime.Now().Add(-4 * time.Second)
48 done := make(chan struct{})
49 go func() {
50 err := cliui.WorkspaceResources(ptty.Output(), []codersdk.WorkspaceResource{{
51 Transition: codersdk.WorkspaceTransitionStart,
52 Type: "google_compute_disk",
53 Name: "root",
54 }, {
55 Transition: codersdk.WorkspaceTransitionStop,
56 Type: "google_compute_disk",
57 Name: "root",
58 }, {
59 Transition: codersdk.WorkspaceTransitionStart,
60 Type: "google_compute_instance",
61 Name: "dev",
62 Agents: []codersdk.WorkspaceAgent{{
63 CreatedAt: dbtime.Now().Add(-10 * time.Second),
64 Status: codersdk.WorkspaceAgentConnecting,
65 LifecycleState: codersdk.WorkspaceAgentLifecycleCreated,
66 Name: "dev",
67 OperatingSystem: "linux",
68 Architecture: "amd64",
69 Health: codersdk.WorkspaceAgentHealth{Healthy: true},
70 }},
71 }, {
72 Transition: codersdk.WorkspaceTransitionStart,

Callers

nothing calls this directly

Calls 7

NewFunction · 0.92
WorkspaceResourcesFunction · 0.92
NowFunction · 0.92
RunMethod · 0.65
OutputMethod · 0.65
AddMethod · 0.65
ExpectMatchMethod · 0.45

Tested by

no test coverage detected