diff --git a/pkg/api/readiness.go b/pkg/api/readiness.go index d7f0d8dd27a..35685483892 100644 --- a/pkg/api/readiness.go +++ b/pkg/api/readiness.go @@ -4,12 +4,27 @@ package api -import "net/http" +import ( + "net/http" + + "github.com/ethersphere/bee/v2" + "github.com/ethersphere/bee/v2/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, + }) } else { - w.WriteHeader(http.StatusBadRequest) + jsonhttp.BadRequest(w, ReadyStatusResponse{ + Status: "notReady", + Version: bee.Version, + APIVersion: Version, + }) } } diff --git a/pkg/api/readiness_test.go b/pkg/api/readiness_test.go index 52677214919..0454f541c2f 100644 --- a/pkg/api/readiness_test.go +++ b/pkg/api/readiness_test.go @@ -37,10 +37,20 @@ 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", + })) // 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", + })) }) }