From 74e9c4c5164bb6da25d6912cd33f5ba542d875f0 Mon Sep 17 00:00:00 2001 From: Gerrit Date: Tue, 2 Apr 2024 11:36:45 +0200 Subject: [PATCH] Allow health services to be omitted. (#138) * Allow health services to be omitted. * Fix tests. --- rest/health.go | 2 +- rest/health_test.go | 30 ++++++++++++------------------ 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/rest/health.go b/rest/health.go index 465ffbd..20e1351 100644 --- a/rest/health.go +++ b/rest/health.go @@ -46,7 +46,7 @@ type HealthResponse struct { // Note that the individual HealthResults evaluated by the HealthCheck interface may again consist of a plurality services. While this is only optional it allows for creating nested health structures. These can be used for more sophisticated scenarios like evaluating platform health describing service availability in different locations or similar. // // If using nested HealthResults, the status of the parent service can be derived automatically from the status of its children by leaving the parent's health status field blank. - Services map[string]HealthResult `json:"services"` + Services map[string]HealthResult `json:"services,omitempty"` } // HealthResult holds the health state of a service. diff --git a/rest/health_test.go b/rest/health_test.go index 5806369..6be1b02 100644 --- a/rest/health_test.go +++ b/rest/health_test.go @@ -24,9 +24,8 @@ func (e *succeedingCheck) Check(ctx context.Context) (HealthResult, error) { Message: "", Services: map[string]HealthResult{ "successPartition": { - Status: HealthStatusHealthy, - Message: "", - Services: map[string]HealthResult{}, + Status: HealthStatusHealthy, + Message: "", }, }, }, nil @@ -43,9 +42,8 @@ func (e *failingCheck) Check(ctx context.Context) (HealthResult, error) { Message: "", Services: map[string]HealthResult{ "failPartition": { - Status: HealthStatusUnhealthy, - Message: "facing an issue", - Services: map[string]HealthResult{}, + Status: HealthStatusUnhealthy, + Message: "facing an issue", }, }, }, fmt.Errorf("facing an issue") @@ -73,9 +71,8 @@ func TestNewHealth(t *testing.T) { h: nil, }, want: &HealthResponse{ - Status: HealthStatusHealthy, - Message: "", - Services: map[string]HealthResult{}, + Status: HealthStatusHealthy, + Message: "", }, }, { @@ -94,9 +91,8 @@ func TestNewHealth(t *testing.T) { Message: "", Services: map[string]HealthResult{ "successPartition": { - Status: HealthStatusHealthy, - Message: "", - Services: map[string]HealthResult{}, + Status: HealthStatusHealthy, + Message: "", }, }, }, @@ -105,9 +101,8 @@ func TestNewHealth(t *testing.T) { Message: "facing an issue", Services: map[string]HealthResult{ "failPartition": { - Status: HealthStatusUnhealthy, - Message: "facing an issue", - Services: map[string]HealthResult{}, + Status: HealthStatusUnhealthy, + Message: "facing an issue", }, }, }, @@ -131,9 +126,8 @@ func TestNewHealth(t *testing.T) { Message: "", Services: map[string]HealthResult{ "successPartition": { - Status: HealthStatusHealthy, - Message: "", - Services: map[string]HealthResult{}, + Status: HealthStatusHealthy, + Message: "", }, }, },