File tree 7 files changed +72
-4
lines changed 7 files changed +72
-4
lines changed Original file line number Diff line number Diff line change @@ -408,7 +408,7 @@ func New(options *Options) *API {
408
408
409
409
if options .HealthcheckFunc == nil {
410
410
options .HealthcheckFunc = func (ctx context.Context , apiKey string ) * healthcheck.Report {
411
- dismissedHealthchecks := loadDismissedHealthcheck (ctx , options .Database , options .Logger )
411
+ dismissedHealthchecks := loadDismissedHealthchecks (ctx , options .Database , options .Logger )
412
412
return healthcheck .Run (ctx , & healthcheck.ReportOptions {
413
413
Database : healthcheck.DatabaseReportOptions {
414
414
DB : options .Database ,
Original file line number Diff line number Diff line change @@ -8,13 +8,12 @@ import (
8
8
"net/http"
9
9
"time"
10
10
11
+ "github.com/google/uuid"
11
12
"golang.org/x/exp/slices"
12
13
"golang.org/x/xerrors"
13
14
14
15
"cdr.dev/slog"
15
16
16
- "github.com/google/uuid"
17
-
18
17
"github.com/coder/coder/v2/coderd/audit"
19
18
"github.com/coder/coder/v2/coderd/database"
20
19
"github.com/coder/coder/v2/coderd/healthcheck"
@@ -256,7 +255,7 @@ func validateHealthSettings(settings codersdk.HealthSettings) error {
256
255
// @x-apidocgen {"skip": true}
257
256
func _debugws (http.ResponseWriter , * http.Request ) {} //nolint:unused
258
257
259
- func loadDismissedHealthcheck (ctx context.Context , db database.Store , logger slog.Logger ) []string {
258
+ func loadDismissedHealthchecks (ctx context.Context , db database.Store , logger slog.Logger ) []string {
260
259
dismissedHealthchecks := []string {}
261
260
settingsJSON , err := db .GetHealthSettings (ctx )
262
261
if err == nil {
Original file line number Diff line number Diff line change @@ -109,6 +109,23 @@ func TestAccessURL(t *testing.T) {
109
109
require .NotNil (t , report .Error )
110
110
assert .Contains (t , * report .Error , expErr .Error ())
111
111
})
112
+
113
+ t .Run ("DismissedError" , func (t * testing.T ) {
114
+ t .Parallel ()
115
+
116
+ var (
117
+ ctx , cancel = context .WithCancel (context .Background ())
118
+ report healthcheck.AccessURLReport
119
+ )
120
+ defer cancel ()
121
+
122
+ report .Run (ctx , & healthcheck.AccessURLReportOptions {
123
+ Dismissed : true ,
124
+ })
125
+
126
+ assert .True (t , report .Dismissed )
127
+ assert .Equal (t , health .SeverityError , report .Severity )
128
+ })
112
129
}
113
130
114
131
type roundTripFunc func (r * http.Request ) (* http.Response , error )
Original file line number Diff line number Diff line change @@ -67,6 +67,26 @@ func TestDatabase(t *testing.T) {
67
67
assert .Contains (t , * report .Error , err .Error ())
68
68
})
69
69
70
+ t .Run ("DismissedError" , func (t * testing.T ) {
71
+ t .Parallel ()
72
+
73
+ var (
74
+ ctx , cancel = context .WithTimeout (context .Background (), testutil .WaitShort )
75
+ report = healthcheck.DatabaseReport {}
76
+ db = dbmock .NewMockStore (gomock .NewController (t ))
77
+ err = xerrors .New ("ping error" )
78
+ )
79
+ defer cancel ()
80
+
81
+ db .EXPECT ().Ping (gomock .Any ()).Return (time .Duration (0 ), err )
82
+
83
+ report .Run (ctx , & healthcheck.DatabaseReportOptions {DB : db , Dismissed : true })
84
+
85
+ assert .Equal (t , health .SeverityError , report .Severity )
86
+ assert .True (t , report .Dismissed )
87
+ require .NotNil (t , report .Error )
88
+ })
89
+
70
90
t .Run ("Median" , func (t * testing.T ) {
71
91
t .Parallel ()
72
92
Original file line number Diff line number Diff line change @@ -120,13 +120,15 @@ func TestDERP(t *testing.T) {
120
120
}},
121
121
},
122
122
}},
123
+ Dismissed : true , // Let's sneak an extra unit test
123
124
}
124
125
)
125
126
126
127
report .Run (ctx , opts )
127
128
128
129
assert .True (t , report .Healthy )
129
130
assert .Equal (t , health .SeverityWarning , report .Severity )
131
+ assert .True (t , report .Dismissed )
130
132
for _ , region := range report .Regions {
131
133
assert .True (t , region .Healthy )
132
134
assert .True (t , region .NodeReports [0 ].Healthy )
Original file line number Diff line number Diff line change @@ -68,4 +68,22 @@ func TestWebsocket(t *testing.T) {
68
68
assert .Equal (t , wsReport .Body , "test error" )
69
69
assert .Equal (t , wsReport .Code , http .StatusBadRequest )
70
70
})
71
+
72
+ t .Run ("DismissedError" , func (t * testing.T ) {
73
+ t .Parallel ()
74
+
75
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitShort )
76
+ defer cancel ()
77
+
78
+ wsReport := healthcheck.WebsocketReport {}
79
+ wsReport .Run (ctx , & healthcheck.WebsocketReportOptions {
80
+ AccessURL : & url.URL {Host : "fake" },
81
+ Dismissed : true ,
82
+ })
83
+
84
+ require .True (t , wsReport .Dismissed )
85
+ require .Equal (t , health .SeverityError , wsReport .Severity )
86
+ require .NotNil (t , wsReport .Error )
87
+ require .Equal (t , health .SeverityError , wsReport .Severity )
88
+ })
71
89
}
Original file line number Diff line number Diff line change @@ -236,3 +236,15 @@ func fakeUpdateProxyHealth(err error) func(context.Context) error {
236
236
return err
237
237
}
238
238
}
239
+
240
+ func TestWorkspaceProxy_Dismissed (t * testing.T ) {
241
+ t .Parallel ()
242
+
243
+ var report healthcheck.WorkspaceProxyReport
244
+ report .Run (context .Background (), & healthcheck.WorkspaceProxyReportOptions {
245
+ Dismissed : true ,
246
+ })
247
+
248
+ assert .True (t , report .Dismissed )
249
+ assert .Equal (t , health .SeverityOK , report .Severity )
250
+ }
You can’t perform that action at this time.
0 commit comments