From 3547dfe74363030b4c29c87a3dc28590a9509d4a Mon Sep 17 00:00:00 2001 From: notanatol Date: Tue, 27 Feb 2024 11:47:56 -0600 Subject: [PATCH] fix: add body to readiness endpoint --- pkg/api/readiness.go | 23 ++++++++++++++++++++--- pkg/api/readiness_test.go | 16 ++++++++++++++-- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/pkg/api/readiness.go b/pkg/api/readiness.go index d7f0d8dd27a..211e3b4f5d1 100644 --- a/pkg/api/readiness.go +++ b/pkg/api/readiness.go @@ -4,12 +4,29 @@ package api -import "net/http" +import ( + "net/http" + + "github.com/ethersphere/bee" + "github.com/ethersphere/bee/pkg/jsonhttp" +) + +type ReadyStatusResponse healthStatusResponse func (s *Service) readinessHandler(w http.ResponseWriter, _ *http.Request) { if s.probe.Ready() == ProbeStatusOK { - w.WriteHeader(http.StatusOK) + jsonhttp.OK(w, ReadyStatusResponse{ + Status: "ready", + Version: bee.Version, + APIVersion: Version, + DebugAPIVersion: DebugVersion, + }) } else { - w.WriteHeader(http.StatusBadRequest) + jsonhttp.BadRequest(w, ReadyStatusResponse{ + Status: "notReady", + Version: bee.Version, + APIVersion: Version, + DebugAPIVersion: DebugVersion, + }) } } diff --git a/pkg/api/readiness_test.go b/pkg/api/readiness_test.go index f91419af8cb..f79303d7157 100644 --- a/pkg/api/readiness_test.go +++ b/pkg/api/readiness_test.go @@ -37,10 +37,22 @@ func TestReadiness(t *testing.T) { // When we set readiness probe to OK it should indicate that API is ready probe.SetReady(api.ProbeStatusOK) - jsonhttptest.Request(t, testServer, http.MethodGet, "/readiness", http.StatusOK) + jsonhttptest.Request(t, testServer, http.MethodGet, "/readiness", http.StatusOK, + jsonhttptest.WithExpectedJSONResponse(api.ReadyStatusResponse{ + Status: "ready", + Version: "-dev", + APIVersion: "0.0.0", + DebugAPIVersion: "0.0.0", + })) // When we set readiness probe to NOK it should indicate that API is not ready probe.SetReady(api.ProbeStatusNOK) - jsonhttptest.Request(t, testServer, http.MethodGet, "/readiness", http.StatusBadRequest) + jsonhttptest.Request(t, testServer, http.MethodGet, "/readiness", http.StatusBadRequest, + jsonhttptest.WithExpectedJSONResponse(api.ReadyStatusResponse{ + Status: "notReady", + Version: "-dev", + APIVersion: "0.0.0", + DebugAPIVersion: "0.0.0", + })) }) }