forked from coder/coder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresources_test.go
More file actions
113 lines (108 loc) · 3.46 KB
/
resources_test.go
File metadata and controls
113 lines (108 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package cliui_test
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/coder/coder/v2/cli/cliui"
"github.com/coder/coder/v2/coderd/database/dbtime"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/pty/ptytest"
)
func TestWorkspaceResources(t *testing.T) {
t.Parallel()
t.Run("SingleAgentSSH", func(t *testing.T) {
t.Parallel()
ptty := ptytest.New(t)
done := make(chan struct{})
go func() {
err := cliui.WorkspaceResources(ptty.Output(), []codersdk.WorkspaceResource{{
Type: "google_compute_instance",
Name: "dev",
Transition: codersdk.WorkspaceTransitionStart,
Agents: []codersdk.WorkspaceAgent{{
Name: "dev",
Status: codersdk.WorkspaceAgentConnected,
LifecycleState: codersdk.WorkspaceAgentLifecycleCreated,
Architecture: "amd64",
OperatingSystem: "linux",
Health: codersdk.WorkspaceAgentHealth{Healthy: true},
}},
}}, cliui.WorkspaceResourcesOptions{
WorkspaceName: "example",
})
assert.NoError(t, err)
close(done)
}()
ptty.ExpectMatch("coder ssh example")
<-done
})
t.Run("MultipleStates", func(t *testing.T) {
t.Parallel()
ptty := ptytest.New(t)
disconnected := dbtime.Now().Add(-4 * time.Second)
done := make(chan struct{})
go func() {
err := cliui.WorkspaceResources(ptty.Output(), []codersdk.WorkspaceResource{{
Transition: codersdk.WorkspaceTransitionStart,
Type: "google_compute_disk",
Name: "root",
}, {
Transition: codersdk.WorkspaceTransitionStop,
Type: "google_compute_disk",
Name: "root",
}, {
Transition: codersdk.WorkspaceTransitionStart,
Type: "google_compute_instance",
Name: "dev",
Agents: []codersdk.WorkspaceAgent{{
CreatedAt: dbtime.Now().Add(-10 * time.Second),
Status: codersdk.WorkspaceAgentConnecting,
LifecycleState: codersdk.WorkspaceAgentLifecycleCreated,
Name: "dev",
OperatingSystem: "linux",
Architecture: "amd64",
Health: codersdk.WorkspaceAgentHealth{Healthy: true},
}},
}, {
Transition: codersdk.WorkspaceTransitionStart,
Type: "kubernetes_pod",
Name: "dev",
Agents: []codersdk.WorkspaceAgent{{
Status: codersdk.WorkspaceAgentConnected,
LifecycleState: codersdk.WorkspaceAgentLifecycleReady,
Name: "go",
Architecture: "amd64",
OperatingSystem: "linux",
Health: codersdk.WorkspaceAgentHealth{Healthy: true},
}, {
DisconnectedAt: &disconnected,
Status: codersdk.WorkspaceAgentDisconnected,
LifecycleState: codersdk.WorkspaceAgentLifecycleReady,
Name: "postgres",
Architecture: "amd64",
OperatingSystem: "linux",
Health: codersdk.WorkspaceAgentHealth{
Healthy: false,
Reason: "agent has lost connection",
},
}},
}}, cliui.WorkspaceResourcesOptions{
WorkspaceName: "dev",
HideAgentState: false,
HideAccess: false,
})
assert.NoError(t, err)
close(done)
}()
ptty.ExpectMatch("google_compute_disk.root")
ptty.ExpectMatch("google_compute_instance.dev")
ptty.ExpectMatch("healthy")
ptty.ExpectMatch("coder ssh dev.dev")
ptty.ExpectMatch("kubernetes_pod.dev")
ptty.ExpectMatch("healthy")
ptty.ExpectMatch("coder ssh dev.go")
ptty.ExpectMatch("agent has lost connection")
ptty.ExpectMatch("coder ssh dev.postgres")
<-done
})
}