Skip to content

Commit

Permalink
feat: add health check response for oohelperd
Browse files Browse the repository at this point in the history
  • Loading branch information
decfox committed Apr 3, 2024
1 parent 130cbd6 commit db66f37
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
15 changes: 14 additions & 1 deletion internal/oohelperd/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,20 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
version.Version,
))

// we only handle the POST method
// handle GET method for health check
if req.Method == "GET" {
metricRequestsCount.WithLabelValues("200", "ok").Inc()
resp := map[string]string{
"message": "Hello OONItarian!",
}
data, err := json.Marshal(resp)
runtimex.PanicOnError(err, "json.Marshal failed")
w.Header().Add("Content-Type", "application/json")
w.Write(data)
return
}

// we only handle the POST method for response generation
if req.Method != "POST" {
metricRequestsCount.WithLabelValues("400", "bad_request_method").Inc()
w.WriteHeader(400)
Expand Down
10 changes: 9 additions & 1 deletion internal/oohelperd/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,20 @@ func TestHandlerWorkingAsIntended(t *testing.T) {

expectations := []expectationSpec{{
name: "check for invalid method",
reqMethod: "GET",
reqMethod: "PUT",
reqContentType: "",
reqBody: strings.NewReader(""),
respStatusCode: 400,
respContentType: "",
parseBody: false,
}, {
name: "check for health message",
reqMethod: "GET",
reqContentType: "",
reqBody: strings.NewReader(""),
respStatusCode: 200,
respContentType: "application/json",
parseBody: true,
}, {
name: "check for error reading request body",
reqMethod: "POST",
Expand Down

0 comments on commit db66f37

Please sign in to comment.