Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b501046

Browse files
authored
test: increase test coverage around health severity (coder#10858)
1 parent 61be4df commit b501046

File tree

1 file changed

+82
-26
lines changed

1 file changed

+82
-26
lines changed

coderd/healthcheck/healthcheck_test.go

+82-26
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/coder/coder/v2/coderd/healthcheck"
1010
"github.com/coder/coder/v2/coderd/healthcheck/derphealth"
11+
"github.com/coder/coder/v2/coderd/healthcheck/health"
1112
)
1213

1314
type testChecker struct {
@@ -40,120 +41,169 @@ func TestHealthcheck(t *testing.T) {
4041
name string
4142
checker *testChecker
4243
healthy bool
44+
severity health.Severity
4345
failingSections []string
4446
}{{
4547
name: "OK",
4648
checker: &testChecker{
4749
DERPReport: derphealth.Report{
48-
Healthy: true,
50+
Healthy: true,
51+
Severity: health.SeverityOK,
4952
},
5053
AccessURLReport: healthcheck.AccessURLReport{
51-
Healthy: true,
54+
Healthy: true,
55+
Severity: health.SeverityOK,
5256
},
5357
WebsocketReport: healthcheck.WebsocketReport{
54-
Healthy: true,
58+
Healthy: true,
59+
Severity: health.SeverityOK,
5560
},
5661
DatabaseReport: healthcheck.DatabaseReport{
57-
Healthy: true,
62+
Healthy: true,
63+
Severity: health.SeverityOK,
5864
},
5965
},
6066
healthy: true,
67+
severity: health.SeverityOK,
6168
failingSections: []string{},
6269
}, {
6370
name: "DERPFail",
6471
checker: &testChecker{
6572
DERPReport: derphealth.Report{
66-
Healthy: false,
73+
Healthy: false,
74+
Severity: health.SeverityError,
6775
},
6876
AccessURLReport: healthcheck.AccessURLReport{
69-
Healthy: true,
77+
Healthy: true,
78+
Severity: health.SeverityOK,
7079
},
7180
WebsocketReport: healthcheck.WebsocketReport{
72-
Healthy: true,
81+
Healthy: true,
82+
Severity: health.SeverityOK,
7383
},
7484
DatabaseReport: healthcheck.DatabaseReport{
75-
Healthy: true,
85+
Healthy: true,
86+
Severity: health.SeverityOK,
7687
},
7788
},
7889
healthy: false,
90+
severity: health.SeverityError,
7991
failingSections: []string{healthcheck.SectionDERP},
8092
}, {
8193
name: "DERPWarning",
8294
checker: &testChecker{
8395
DERPReport: derphealth.Report{
8496
Healthy: true,
8597
Warnings: []string{"foobar"},
98+
Severity: health.SeverityWarning,
8699
},
87100
AccessURLReport: healthcheck.AccessURLReport{
88-
Healthy: true,
101+
Healthy: true,
102+
Severity: health.SeverityOK,
89103
},
90104
WebsocketReport: healthcheck.WebsocketReport{
91-
Healthy: true,
105+
Healthy: true,
106+
Severity: health.SeverityOK,
92107
},
93108
DatabaseReport: healthcheck.DatabaseReport{
94-
Healthy: true,
109+
Healthy: true,
110+
Severity: health.SeverityOK,
95111
},
96112
},
97113
healthy: true,
114+
severity: health.SeverityWarning,
98115
failingSections: []string{},
99116
}, {
100117
name: "AccessURLFail",
101118
checker: &testChecker{
102119
DERPReport: derphealth.Report{
103-
Healthy: true,
120+
Healthy: true,
121+
Severity: health.SeverityOK,
104122
},
105123
AccessURLReport: healthcheck.AccessURLReport{
106-
Healthy: false,
124+
Healthy: false,
125+
Severity: health.SeverityWarning,
107126
},
108127
WebsocketReport: healthcheck.WebsocketReport{
109-
Healthy: true,
128+
Healthy: true,
129+
Severity: health.SeverityOK,
110130
},
111131
DatabaseReport: healthcheck.DatabaseReport{
112-
Healthy: true,
132+
Healthy: true,
133+
Severity: health.SeverityOK,
113134
},
114135
},
115136
healthy: false,
137+
severity: health.SeverityWarning,
116138
failingSections: []string{healthcheck.SectionAccessURL},
117139
}, {
118140
name: "WebsocketFail",
119141
checker: &testChecker{
120142
DERPReport: derphealth.Report{
121-
Healthy: true,
143+
Healthy: true,
144+
Severity: health.SeverityOK,
122145
},
123146
AccessURLReport: healthcheck.AccessURLReport{
124-
Healthy: true,
147+
Healthy: true,
148+
Severity: health.SeverityOK,
125149
},
126150
WebsocketReport: healthcheck.WebsocketReport{
127-
Healthy: false,
151+
Healthy: false,
152+
Severity: health.SeverityError,
128153
},
129154
DatabaseReport: healthcheck.DatabaseReport{
130-
Healthy: true,
155+
Healthy: true,
156+
Severity: health.SeverityOK,
131157
},
132158
},
133159
healthy: false,
160+
severity: health.SeverityError,
134161
failingSections: []string{healthcheck.SectionWebsocket},
135162
}, {
136163
name: "DatabaseFail",
137164
checker: &testChecker{
138165
DERPReport: derphealth.Report{
139-
Healthy: true,
166+
Healthy: true,
167+
Severity: health.SeverityOK,
140168
},
141169
AccessURLReport: healthcheck.AccessURLReport{
142-
Healthy: true,
170+
Healthy: true,
171+
Severity: health.SeverityOK,
143172
},
144173
WebsocketReport: healthcheck.WebsocketReport{
145-
Healthy: true,
174+
Healthy: true,
175+
Severity: health.SeverityOK,
146176
},
147177
DatabaseReport: healthcheck.DatabaseReport{
148-
Healthy: false,
178+
Healthy: false,
179+
Severity: health.SeverityError,
149180
},
150181
},
151182
healthy: false,
183+
severity: health.SeverityError,
152184
failingSections: []string{healthcheck.SectionDatabase},
153185
}, {
154-
name: "AllFail",
155-
checker: &testChecker{},
156-
healthy: false,
186+
name: "AllFail",
187+
checker: &testChecker{
188+
DERPReport: derphealth.Report{
189+
Healthy: false,
190+
Severity: health.SeverityError,
191+
},
192+
AccessURLReport: healthcheck.AccessURLReport{
193+
Healthy: false,
194+
Severity: health.SeverityError,
195+
},
196+
WebsocketReport: healthcheck.WebsocketReport{
197+
Healthy: false,
198+
Severity: health.SeverityError,
199+
},
200+
DatabaseReport: healthcheck.DatabaseReport{
201+
Healthy: false,
202+
Severity: health.SeverityError,
203+
},
204+
},
205+
healthy: false,
206+
severity: health.SeverityError,
157207
failingSections: []string{
158208
healthcheck.SectionDERP,
159209
healthcheck.SectionAccessURL,
@@ -170,11 +220,17 @@ func TestHealthcheck(t *testing.T) {
170220
})
171221

172222
assert.Equal(t, c.healthy, report.Healthy)
223+
assert.Equal(t, c.severity, report.Severity)
173224
assert.Equal(t, c.failingSections, report.FailingSections)
174225
assert.Equal(t, c.checker.DERPReport.Healthy, report.DERP.Healthy)
226+
assert.Equal(t, c.checker.DERPReport.Severity, report.DERP.Severity)
175227
assert.Equal(t, c.checker.DERPReport.Warnings, report.DERP.Warnings)
176228
assert.Equal(t, c.checker.AccessURLReport.Healthy, report.AccessURL.Healthy)
229+
assert.Equal(t, c.checker.AccessURLReport.Severity, report.AccessURL.Severity)
177230
assert.Equal(t, c.checker.WebsocketReport.Healthy, report.Websocket.Healthy)
231+
assert.Equal(t, c.checker.WebsocketReport.Severity, report.Websocket.Severity)
232+
assert.Equal(t, c.checker.DatabaseReport.Healthy, report.Database.Healthy)
233+
assert.Equal(t, c.checker.DatabaseReport.Severity, report.Database.Severity)
178234
assert.NotZero(t, report.Time)
179235
assert.NotZero(t, report.CoderVersion)
180236
})

0 commit comments

Comments
 (0)