Compare commits

..

2 Commits

2 changed files with 14 additions and 4 deletions

View File

@@ -35,12 +35,17 @@ type OverallResult struct {
func determineOverallStatus(results map[string]Result) Status { func determineOverallStatus(results map[string]Result) Status {
hasUnhealthy := false hasUnhealthy := false
hasSMTPUnhealthy := false
hasDegraded := false hasDegraded := false
for _, result := range results { for name, result := range results {
switch result.Status { switch result.Status {
case StatusUnhealthy: case StatusUnhealthy:
if name == "smtp" {
hasSMTPUnhealthy = true
} else {
hasUnhealthy = true hasUnhealthy = true
}
case StatusDegraded: case StatusDegraded:
hasDegraded = true hasDegraded = true
} }
@@ -49,7 +54,7 @@ func determineOverallStatus(results map[string]Result) Status {
if hasUnhealthy { if hasUnhealthy {
return StatusUnhealthy return StatusUnhealthy
} }
if hasDegraded { if hasDegraded || hasSMTPUnhealthy {
return StatusDegraded return StatusDegraded
} }
return StatusHealthy return StatusHealthy

View File

@@ -57,10 +57,15 @@ func TestDetermineOverallStatus(t *testing.T) {
results: map[string]Result{"db": {Status: StatusUnhealthy}, "smtp": {Status: StatusHealthy}}, results: map[string]Result{"db": {Status: StatusUnhealthy}, "smtp": {Status: StatusHealthy}},
expected: StatusUnhealthy, expected: StatusUnhealthy,
}, },
{
name: "smtp unhealthy downgrades overall to degraded",
results: map[string]Result{"db": {Status: StatusHealthy}, "smtp": {Status: StatusUnhealthy}},
expected: StatusDegraded,
},
{ {
name: "mixed degraded and unhealthy", name: "mixed degraded and unhealthy",
results: map[string]Result{"db": {Status: StatusDegraded}, "smtp": {Status: StatusUnhealthy}}, results: map[string]Result{"db": {Status: StatusDegraded}, "smtp": {Status: StatusUnhealthy}},
expected: StatusUnhealthy, expected: StatusDegraded,
}, },
{ {
name: "empty results", name: "empty results",