8
8
9
9
"github.com/coder/coder/v2/coderd/healthcheck"
10
10
"github.com/coder/coder/v2/coderd/healthcheck/derphealth"
11
+ "github.com/coder/coder/v2/coderd/healthcheck/health"
11
12
)
12
13
13
14
type testChecker struct {
@@ -40,120 +41,169 @@ func TestHealthcheck(t *testing.T) {
40
41
name string
41
42
checker * testChecker
42
43
healthy bool
44
+ severity health.Severity
43
45
failingSections []string
44
46
}{{
45
47
name :"OK" ,
46
48
checker :& testChecker {
47
49
DERPReport : derphealth.Report {
48
- Healthy :true ,
50
+ Healthy :true ,
51
+ Severity :health .SeverityOK ,
49
52
},
50
53
AccessURLReport : healthcheck.AccessURLReport {
51
- Healthy :true ,
54
+ Healthy :true ,
55
+ Severity :health .SeverityOK ,
52
56
},
53
57
WebsocketReport : healthcheck.WebsocketReport {
54
- Healthy :true ,
58
+ Healthy :true ,
59
+ Severity :health .SeverityOK ,
55
60
},
56
61
DatabaseReport : healthcheck.DatabaseReport {
57
- Healthy :true ,
62
+ Healthy :true ,
63
+ Severity :health .SeverityOK ,
58
64
},
59
65
},
60
66
healthy :true ,
67
+ severity :health .SeverityOK ,
61
68
failingSections : []string {},
62
69
}, {
63
70
name :"DERPFail" ,
64
71
checker :& testChecker {
65
72
DERPReport : derphealth.Report {
66
- Healthy :false ,
73
+ Healthy :false ,
74
+ Severity :health .SeverityError ,
67
75
},
68
76
AccessURLReport : healthcheck.AccessURLReport {
69
- Healthy :true ,
77
+ Healthy :true ,
78
+ Severity :health .SeverityOK ,
70
79
},
71
80
WebsocketReport : healthcheck.WebsocketReport {
72
- Healthy :true ,
81
+ Healthy :true ,
82
+ Severity :health .SeverityOK ,
73
83
},
74
84
DatabaseReport : healthcheck.DatabaseReport {
75
- Healthy :true ,
85
+ Healthy :true ,
86
+ Severity :health .SeverityOK ,
76
87
},
77
88
},
78
89
healthy :false ,
90
+ severity :health .SeverityError ,
79
91
failingSections : []string {healthcheck .SectionDERP },
80
92
}, {
81
93
name :"DERPWarning" ,
82
94
checker :& testChecker {
83
95
DERPReport : derphealth.Report {
84
96
Healthy :true ,
85
97
Warnings : []string {"foobar" },
98
+ Severity :health .SeverityWarning ,
86
99
},
87
100
AccessURLReport : healthcheck.AccessURLReport {
88
- Healthy :true ,
101
+ Healthy :true ,
102
+ Severity :health .SeverityOK ,
89
103
},
90
104
WebsocketReport : healthcheck.WebsocketReport {
91
- Healthy :true ,
105
+ Healthy :true ,
106
+ Severity :health .SeverityOK ,
92
107
},
93
108
DatabaseReport : healthcheck.DatabaseReport {
94
- Healthy :true ,
109
+ Healthy :true ,
110
+ Severity :health .SeverityOK ,
95
111
},
96
112
},
97
113
healthy :true ,
114
+ severity :health .SeverityWarning ,
98
115
failingSections : []string {},
99
116
}, {
100
117
name :"AccessURLFail" ,
101
118
checker :& testChecker {
102
119
DERPReport : derphealth.Report {
103
- Healthy :true ,
120
+ Healthy :true ,
121
+ Severity :health .SeverityOK ,
104
122
},
105
123
AccessURLReport : healthcheck.AccessURLReport {
106
- Healthy :false ,
124
+ Healthy :false ,
125
+ Severity :health .SeverityWarning ,
107
126
},
108
127
WebsocketReport : healthcheck.WebsocketReport {
109
- Healthy :true ,
128
+ Healthy :true ,
129
+ Severity :health .SeverityOK ,
110
130
},
111
131
DatabaseReport : healthcheck.DatabaseReport {
112
- Healthy :true ,
132
+ Healthy :true ,
133
+ Severity :health .SeverityOK ,
113
134
},
114
135
},
115
136
healthy :false ,
137
+ severity :health .SeverityWarning ,
116
138
failingSections : []string {healthcheck .SectionAccessURL },
117
139
}, {
118
140
name :"WebsocketFail" ,
119
141
checker :& testChecker {
120
142
DERPReport : derphealth.Report {
121
- Healthy :true ,
143
+ Healthy :true ,
144
+ Severity :health .SeverityOK ,
122
145
},
123
146
AccessURLReport : healthcheck.AccessURLReport {
124
- Healthy :true ,
147
+ Healthy :true ,
148
+ Severity :health .SeverityOK ,
125
149
},
126
150
WebsocketReport : healthcheck.WebsocketReport {
127
- Healthy :false ,
151
+ Healthy :false ,
152
+ Severity :health .SeverityError ,
128
153
},
129
154
DatabaseReport : healthcheck.DatabaseReport {
130
- Healthy :true ,
155
+ Healthy :true ,
156
+ Severity :health .SeverityOK ,
131
157
},
132
158
},
133
159
healthy :false ,
160
+ severity :health .SeverityError ,
134
161
failingSections : []string {healthcheck .SectionWebsocket },
135
162
}, {
136
163
name :"DatabaseFail" ,
137
164
checker :& testChecker {
138
165
DERPReport : derphealth.Report {
139
- Healthy :true ,
166
+ Healthy :true ,
167
+ Severity :health .SeverityOK ,
140
168
},
141
169
AccessURLReport : healthcheck.AccessURLReport {
142
- Healthy :true ,
170
+ Healthy :true ,
171
+ Severity :health .SeverityOK ,
143
172
},
144
173
WebsocketReport : healthcheck.WebsocketReport {
145
- Healthy :true ,
174
+ Healthy :true ,
175
+ Severity :health .SeverityOK ,
146
176
},
147
177
DatabaseReport : healthcheck.DatabaseReport {
148
- Healthy :false ,
178
+ Healthy :false ,
179
+ Severity :health .SeverityError ,
149
180
},
150
181
},
151
182
healthy :false ,
183
+ severity :health .SeverityError ,
152
184
failingSections : []string {healthcheck .SectionDatabase },
153
185
}, {
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 ,
157
207
failingSections : []string {
158
208
healthcheck .SectionDERP ,
159
209
healthcheck .SectionAccessURL ,
@@ -170,11 +220,17 @@ func TestHealthcheck(t *testing.T) {
170
220
})
171
221
172
222
assert .Equal (t ,c .healthy ,report .Healthy )
223
+ assert .Equal (t ,c .severity ,report .Severity )
173
224
assert .Equal (t ,c .failingSections ,report .FailingSections )
174
225
assert .Equal (t ,c .checker .DERPReport .Healthy ,report .DERP .Healthy )
226
+ assert .Equal (t ,c .checker .DERPReport .Severity ,report .DERP .Severity )
175
227
assert .Equal (t ,c .checker .DERPReport .Warnings ,report .DERP .Warnings )
176
228
assert .Equal (t ,c .checker .AccessURLReport .Healthy ,report .AccessURL .Healthy )
229
+ assert .Equal (t ,c .checker .AccessURLReport .Severity ,report .AccessURL .Severity )
177
230
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 )
178
234
assert .NotZero (t ,report .Time )
179
235
assert .NotZero (t ,report .CoderVersion )
180
236
})