mirror of https://github.com/coder/coder.git
test: increase test coverage around health severity (#10858)
This commit is contained in:
parent
61be4dfe5a
commit
b501046cf9
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
"github.com/coder/coder/v2/coderd/healthcheck"
|
||||
"github.com/coder/coder/v2/coderd/healthcheck/derphealth"
|
||||
"github.com/coder/coder/v2/coderd/healthcheck/health"
|
||||
)
|
||||
|
||||
type testChecker struct {
|
||||
|
@ -40,42 +41,53 @@ func TestHealthcheck(t *testing.T) {
|
|||
name string
|
||||
checker *testChecker
|
||||
healthy bool
|
||||
severity health.Severity
|
||||
failingSections []string
|
||||
}{{
|
||||
name: "OK",
|
||||
checker: &testChecker{
|
||||
DERPReport: derphealth.Report{
|
||||
Healthy: true,
|
||||
Healthy: true,
|
||||
Severity: health.SeverityOK,
|
||||
},
|
||||
AccessURLReport: healthcheck.AccessURLReport{
|
||||
Healthy: true,
|
||||
Healthy: true,
|
||||
Severity: health.SeverityOK,
|
||||
},
|
||||
WebsocketReport: healthcheck.WebsocketReport{
|
||||
Healthy: true,
|
||||
Healthy: true,
|
||||
Severity: health.SeverityOK,
|
||||
},
|
||||
DatabaseReport: healthcheck.DatabaseReport{
|
||||
Healthy: true,
|
||||
Healthy: true,
|
||||
Severity: health.SeverityOK,
|
||||
},
|
||||
},
|
||||
healthy: true,
|
||||
severity: health.SeverityOK,
|
||||
failingSections: []string{},
|
||||
}, {
|
||||
name: "DERPFail",
|
||||
checker: &testChecker{
|
||||
DERPReport: derphealth.Report{
|
||||
Healthy: false,
|
||||
Healthy: false,
|
||||
Severity: health.SeverityError,
|
||||
},
|
||||
AccessURLReport: healthcheck.AccessURLReport{
|
||||
Healthy: true,
|
||||
Healthy: true,
|
||||
Severity: health.SeverityOK,
|
||||
},
|
||||
WebsocketReport: healthcheck.WebsocketReport{
|
||||
Healthy: true,
|
||||
Healthy: true,
|
||||
Severity: health.SeverityOK,
|
||||
},
|
||||
DatabaseReport: healthcheck.DatabaseReport{
|
||||
Healthy: true,
|
||||
Healthy: true,
|
||||
Severity: health.SeverityOK,
|
||||
},
|
||||
},
|
||||
healthy: false,
|
||||
severity: health.SeverityError,
|
||||
failingSections: []string{healthcheck.SectionDERP},
|
||||
}, {
|
||||
name: "DERPWarning",
|
||||
|
@ -83,77 +95,115 @@ func TestHealthcheck(t *testing.T) {
|
|||
DERPReport: derphealth.Report{
|
||||
Healthy: true,
|
||||
Warnings: []string{"foobar"},
|
||||
Severity: health.SeverityWarning,
|
||||
},
|
||||
AccessURLReport: healthcheck.AccessURLReport{
|
||||
Healthy: true,
|
||||
Healthy: true,
|
||||
Severity: health.SeverityOK,
|
||||
},
|
||||
WebsocketReport: healthcheck.WebsocketReport{
|
||||
Healthy: true,
|
||||
Healthy: true,
|
||||
Severity: health.SeverityOK,
|
||||
},
|
||||
DatabaseReport: healthcheck.DatabaseReport{
|
||||
Healthy: true,
|
||||
Healthy: true,
|
||||
Severity: health.SeverityOK,
|
||||
},
|
||||
},
|
||||
healthy: true,
|
||||
severity: health.SeverityWarning,
|
||||
failingSections: []string{},
|
||||
}, {
|
||||
name: "AccessURLFail",
|
||||
checker: &testChecker{
|
||||
DERPReport: derphealth.Report{
|
||||
Healthy: true,
|
||||
Healthy: true,
|
||||
Severity: health.SeverityOK,
|
||||
},
|
||||
AccessURLReport: healthcheck.AccessURLReport{
|
||||
Healthy: false,
|
||||
Healthy: false,
|
||||
Severity: health.SeverityWarning,
|
||||
},
|
||||
WebsocketReport: healthcheck.WebsocketReport{
|
||||
Healthy: true,
|
||||
Healthy: true,
|
||||
Severity: health.SeverityOK,
|
||||
},
|
||||
DatabaseReport: healthcheck.DatabaseReport{
|
||||
Healthy: true,
|
||||
Healthy: true,
|
||||
Severity: health.SeverityOK,
|
||||
},
|
||||
},
|
||||
healthy: false,
|
||||
severity: health.SeverityWarning,
|
||||
failingSections: []string{healthcheck.SectionAccessURL},
|
||||
}, {
|
||||
name: "WebsocketFail",
|
||||
checker: &testChecker{
|
||||
DERPReport: derphealth.Report{
|
||||
Healthy: true,
|
||||
Healthy: true,
|
||||
Severity: health.SeverityOK,
|
||||
},
|
||||
AccessURLReport: healthcheck.AccessURLReport{
|
||||
Healthy: true,
|
||||
Healthy: true,
|
||||
Severity: health.SeverityOK,
|
||||
},
|
||||
WebsocketReport: healthcheck.WebsocketReport{
|
||||
Healthy: false,
|
||||
Healthy: false,
|
||||
Severity: health.SeverityError,
|
||||
},
|
||||
DatabaseReport: healthcheck.DatabaseReport{
|
||||
Healthy: true,
|
||||
Healthy: true,
|
||||
Severity: health.SeverityOK,
|
||||
},
|
||||
},
|
||||
healthy: false,
|
||||
severity: health.SeverityError,
|
||||
failingSections: []string{healthcheck.SectionWebsocket},
|
||||
}, {
|
||||
name: "DatabaseFail",
|
||||
checker: &testChecker{
|
||||
DERPReport: derphealth.Report{
|
||||
Healthy: true,
|
||||
Healthy: true,
|
||||
Severity: health.SeverityOK,
|
||||
},
|
||||
AccessURLReport: healthcheck.AccessURLReport{
|
||||
Healthy: true,
|
||||
Healthy: true,
|
||||
Severity: health.SeverityOK,
|
||||
},
|
||||
WebsocketReport: healthcheck.WebsocketReport{
|
||||
Healthy: true,
|
||||
Healthy: true,
|
||||
Severity: health.SeverityOK,
|
||||
},
|
||||
DatabaseReport: healthcheck.DatabaseReport{
|
||||
Healthy: false,
|
||||
Healthy: false,
|
||||
Severity: health.SeverityError,
|
||||
},
|
||||
},
|
||||
healthy: false,
|
||||
severity: health.SeverityError,
|
||||
failingSections: []string{healthcheck.SectionDatabase},
|
||||
}, {
|
||||
name: "AllFail",
|
||||
checker: &testChecker{},
|
||||
healthy: false,
|
||||
name: "AllFail",
|
||||
checker: &testChecker{
|
||||
DERPReport: derphealth.Report{
|
||||
Healthy: false,
|
||||
Severity: health.SeverityError,
|
||||
},
|
||||
AccessURLReport: healthcheck.AccessURLReport{
|
||||
Healthy: false,
|
||||
Severity: health.SeverityError,
|
||||
},
|
||||
WebsocketReport: healthcheck.WebsocketReport{
|
||||
Healthy: false,
|
||||
Severity: health.SeverityError,
|
||||
},
|
||||
DatabaseReport: healthcheck.DatabaseReport{
|
||||
Healthy: false,
|
||||
Severity: health.SeverityError,
|
||||
},
|
||||
},
|
||||
healthy: false,
|
||||
severity: health.SeverityError,
|
||||
failingSections: []string{
|
||||
healthcheck.SectionDERP,
|
||||
healthcheck.SectionAccessURL,
|
||||
|
@ -170,11 +220,17 @@ func TestHealthcheck(t *testing.T) {
|
|||
})
|
||||
|
||||
assert.Equal(t, c.healthy, report.Healthy)
|
||||
assert.Equal(t, c.severity, report.Severity)
|
||||
assert.Equal(t, c.failingSections, report.FailingSections)
|
||||
assert.Equal(t, c.checker.DERPReport.Healthy, report.DERP.Healthy)
|
||||
assert.Equal(t, c.checker.DERPReport.Severity, report.DERP.Severity)
|
||||
assert.Equal(t, c.checker.DERPReport.Warnings, report.DERP.Warnings)
|
||||
assert.Equal(t, c.checker.AccessURLReport.Healthy, report.AccessURL.Healthy)
|
||||
assert.Equal(t, c.checker.AccessURLReport.Severity, report.AccessURL.Severity)
|
||||
assert.Equal(t, c.checker.WebsocketReport.Healthy, report.Websocket.Healthy)
|
||||
assert.Equal(t, c.checker.WebsocketReport.Severity, report.Websocket.Severity)
|
||||
assert.Equal(t, c.checker.DatabaseReport.Healthy, report.Database.Healthy)
|
||||
assert.Equal(t, c.checker.DatabaseReport.Severity, report.Database.Severity)
|
||||
assert.NotZero(t, report.Time)
|
||||
assert.NotZero(t, report.CoderVersion)
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue