@@ -14,12 +14,6 @@ import (
14
14
func TestWorkspaceProxies (t * testing.T ) {
15
15
t .Parallel ()
16
16
17
- var (
18
- newerPatchVersion = "v2.34.6"
19
- currentVersion = "v2.34.5"
20
- olderVersion = "v2.33.0"
21
- )
22
-
23
17
for _ , tt := range []struct {
24
18
name string
25
19
fetchWorkspaceProxies func (context.Context ) (codersdk.RegionsResponse [codersdk.WorkspaceProxy ], error )
@@ -43,14 +37,14 @@ func TestWorkspaceProxies(t *testing.T) {
43
37
},
44
38
{
45
39
name : "Enabled/OneHealthy" ,
46
- fetchWorkspaceProxies : fakeFetchWorkspaceProxies (fakeWorkspaceProxy ("alpha" , true , currentVersion )),
40
+ fetchWorkspaceProxies : fakeFetchWorkspaceProxies (fakeWorkspaceProxy ("alpha" , true )),
47
41
updateProxyHealth : fakeUpdateProxyHealth (nil ),
48
42
expectedHealthy : true ,
49
43
expectedSeverity : health .SeverityOK ,
50
44
},
51
45
{
52
46
name : "Enabled/OneUnhealthy" ,
53
- fetchWorkspaceProxies : fakeFetchWorkspaceProxies (fakeWorkspaceProxy ("alpha" , false , currentVersion )),
47
+ fetchWorkspaceProxies : fakeFetchWorkspaceProxies (fakeWorkspaceProxy ("alpha" , false )),
54
48
updateProxyHealth : fakeUpdateProxyHealth (nil ),
55
49
expectedHealthy : false ,
56
50
expectedSeverity : health .SeverityError ,
@@ -66,7 +60,6 @@ func TestWorkspaceProxies(t *testing.T) {
66
60
Name : "gone" ,
67
61
Healthy : false ,
68
62
},
69
- Version : currentVersion ,
70
63
Status : codersdk.WorkspaceProxyStatus {
71
64
Status : codersdk .ProxyUnreachable ,
72
65
Report : codersdk.ProxyHealthReport {
@@ -87,8 +80,8 @@ func TestWorkspaceProxies(t *testing.T) {
87
80
{
88
81
name : "Enabled/AllHealthy" ,
89
82
fetchWorkspaceProxies : fakeFetchWorkspaceProxies (
90
- fakeWorkspaceProxy ("alpha" , true , currentVersion ),
91
- fakeWorkspaceProxy ("beta" , true , currentVersion ),
83
+ fakeWorkspaceProxy ("alpha" , true ),
84
+ fakeWorkspaceProxy ("beta" , true ),
92
85
),
93
86
updateProxyHealth : func (ctx context.Context ) error {
94
87
return nil
@@ -99,8 +92,8 @@ func TestWorkspaceProxies(t *testing.T) {
99
92
{
100
93
name : "Enabled/OneHealthyOneUnhealthy" ,
101
94
fetchWorkspaceProxies : fakeFetchWorkspaceProxies (
102
- fakeWorkspaceProxy ("alpha" , false , currentVersion ),
103
- fakeWorkspaceProxy ("beta" , true , currentVersion ),
95
+ fakeWorkspaceProxy ("alpha" , false ),
96
+ fakeWorkspaceProxy ("beta" , true ),
104
97
),
105
98
updateProxyHealth : fakeUpdateProxyHealth (nil ),
106
99
expectedHealthy : true ,
@@ -110,39 +103,18 @@ func TestWorkspaceProxies(t *testing.T) {
110
103
{
111
104
name : "Enabled/AllUnhealthy" ,
112
105
fetchWorkspaceProxies : fakeFetchWorkspaceProxies (
113
- fakeWorkspaceProxy ("alpha" , false , currentVersion ),
114
- fakeWorkspaceProxy ("beta" , false , currentVersion ),
106
+ fakeWorkspaceProxy ("alpha" , false ),
107
+ fakeWorkspaceProxy ("beta" , false ),
115
108
),
116
109
updateProxyHealth : fakeUpdateProxyHealth (nil ),
117
110
expectedHealthy : false ,
118
111
expectedSeverity : health .SeverityError ,
119
112
expectedError : string (health .CodeProxyUnhealthy ),
120
113
},
121
- {
122
- name : "Enabled/OneOutOfDate" ,
123
- fetchWorkspaceProxies : fakeFetchWorkspaceProxies (
124
- fakeWorkspaceProxy ("alpha" , true , currentVersion ),
125
- fakeWorkspaceProxy ("beta" , true , olderVersion ),
126
- ),
127
- updateProxyHealth : fakeUpdateProxyHealth (nil ),
128
- expectedHealthy : false ,
129
- expectedSeverity : health .SeverityError ,
130
- expectedError : `proxy "beta" version "v2.33.0" does not match primary server version "v2.34.5"` ,
131
- },
132
- {
133
- name : "Enabled/OneSlightlyNewerButStillOK" ,
134
- fetchWorkspaceProxies : fakeFetchWorkspaceProxies (
135
- fakeWorkspaceProxy ("alpha" , true , currentVersion ),
136
- fakeWorkspaceProxy ("beta" , true , newerPatchVersion ),
137
- ),
138
- updateProxyHealth : fakeUpdateProxyHealth (nil ),
139
- expectedHealthy : true ,
140
- expectedSeverity : health .SeverityOK ,
141
- },
142
114
{
143
115
name : "Enabled/NotConnectedYet" ,
144
116
fetchWorkspaceProxies : fakeFetchWorkspaceProxies (
145
- fakeWorkspaceProxy ("slowpoke" , true , "" ),
117
+ fakeWorkspaceProxy ("slowpoke" , true ),
146
118
),
147
119
updateProxyHealth : fakeUpdateProxyHealth (nil ),
148
120
expectedHealthy : true ,
@@ -158,28 +130,56 @@ func TestWorkspaceProxies(t *testing.T) {
158
130
},
159
131
{
160
132
name : "Enabled/ErrUpdateProxyHealth" ,
161
- fetchWorkspaceProxies : fakeFetchWorkspaceProxies (fakeWorkspaceProxy ("alpha" , true , currentVersion )),
133
+ fetchWorkspaceProxies : fakeFetchWorkspaceProxies (fakeWorkspaceProxy ("alpha" , true )),
162
134
updateProxyHealth : fakeUpdateProxyHealth (assert .AnError ),
163
135
expectedHealthy : true ,
164
136
expectedSeverity : health .SeverityWarning ,
165
137
expectedWarningCode : health .CodeProxyUpdate ,
166
138
},
167
139
{
168
140
name : "Enabled/OneUnhealthyAndDeleted" ,
169
- fetchWorkspaceProxies : fakeFetchWorkspaceProxies (fakeWorkspaceProxy ("alpha" , false , currentVersion , func (wp * codersdk.WorkspaceProxy ) {
141
+ fetchWorkspaceProxies : fakeFetchWorkspaceProxies (fakeWorkspaceProxy ("alpha" , false , func (wp * codersdk.WorkspaceProxy ) {
170
142
wp .Deleted = true
171
143
})),
172
144
updateProxyHealth : fakeUpdateProxyHealth (nil ),
173
145
expectedHealthy : true ,
174
146
expectedSeverity : health .SeverityOK ,
175
147
},
148
+ {
149
+ name : "Enabled/ProxyWarnings" ,
150
+ fetchWorkspaceProxies : fakeFetchWorkspaceProxies (
151
+ fakeWorkspaceProxy ("alpha" , true , func (wp * codersdk.WorkspaceProxy ) {
152
+ wp .Status .Report .Warnings = []string {"warning" }
153
+ }),
154
+ fakeWorkspaceProxy ("beta" , false ),
155
+ ),
156
+ updateProxyHealth : fakeUpdateProxyHealth (nil ),
157
+ expectedHealthy : true ,
158
+ expectedSeverity : health .SeverityWarning ,
159
+ expectedWarningCode : health .CodeProxyUnhealthy ,
160
+ },
161
+ {
162
+ name : "Enabled/ProxyWarningsButAllErrored" ,
163
+ fetchWorkspaceProxies : fakeFetchWorkspaceProxies (
164
+ fakeWorkspaceProxy ("alpha" , false ),
165
+ fakeWorkspaceProxy ("beta" , false , func (wp * codersdk.WorkspaceProxy ) {
166
+ wp .Status .Report .Warnings = []string {"warning" }
167
+ }),
168
+ ),
169
+ updateProxyHealth : fakeUpdateProxyHealth (nil ),
170
+ expectedHealthy : false ,
171
+ expectedError : string (health .CodeProxyUnhealthy ),
172
+ expectedSeverity : health .SeverityError ,
173
+ },
176
174
} {
177
175
tt := tt
176
+ if tt .name != "Enabled/ProxyWarnings" {
177
+ continue
178
+ }
178
179
t .Run (tt .name , func (t * testing.T ) {
179
180
t .Parallel ()
180
181
var rpt healthcheck.WorkspaceProxyReport
181
182
var opts healthcheck.WorkspaceProxyReportOptions
182
- opts .CurrentVersion = currentVersion
183
183
if tt .fetchWorkspaceProxies != nil && tt .updateProxyHealth != nil {
184
184
opts .WorkspaceProxiesFetchUpdater = & fakeWorkspaceProxyFetchUpdater {
185
185
fetchFunc : tt .fetchWorkspaceProxies ,
@@ -196,7 +196,9 @@ func TestWorkspaceProxies(t *testing.T) {
196
196
if tt .expectedError != "" && assert .NotNil (t , rpt .Error ) {
197
197
assert .Contains (t , * rpt .Error , tt .expectedError )
198
198
} else {
199
- assert .Nil (t , rpt .Error )
199
+ if ! assert .Nil (t , rpt .Error ) {
200
+ t .Logf ("error: %v" , * rpt .Error )
201
+ }
200
202
}
201
203
if tt .expectedWarningCode != "" && assert .NotEmpty (t , rpt .Warnings ) {
202
204
var found bool
@@ -245,7 +247,7 @@ func (u *fakeWorkspaceProxyFetchUpdater) Update(ctx context.Context) error {
245
247
}
246
248
247
249
//nolint:revive // yes, this is a control flag, and that is OK in a unit test.
248
- func fakeWorkspaceProxy (name string , healthy bool , version string , mutators ... func (* codersdk.WorkspaceProxy )) codersdk.WorkspaceProxy {
250
+ func fakeWorkspaceProxy (name string , healthy bool , mutators ... func (* codersdk.WorkspaceProxy )) codersdk.WorkspaceProxy {
249
251
var status codersdk.WorkspaceProxyStatus
250
252
if ! healthy {
251
253
status = codersdk.WorkspaceProxyStatus {
@@ -260,8 +262,7 @@ func fakeWorkspaceProxy(name string, healthy bool, version string, mutators ...f
260
262
Name : name ,
261
263
Healthy : healthy ,
262
264
},
263
- Version : version ,
264
- Status : status ,
265
+ Status : status ,
265
266
}
266
267
for _ , f := range mutators {
267
268
f (& wsp )
0 commit comments