Skip to content

Commit

Permalink
Merge pull request #4 from Rindrics/add-health-check
Browse files Browse the repository at this point in the history
Add endpoint `/health` for health checking
  • Loading branch information
m-mizutani authored Aug 5, 2023
2 parents 53b5583 + 47b9837 commit a8d378d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/controller/server/healthcheck.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package server

import "net/http"

func handleHealthCheckRequest() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("OK"))
}
}
20 changes: 20 additions & 0 deletions pkg/controller/server/healthcheck_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package server_test

import (
"net/http/httptest"
"testing"

"github.com/m-mizutani/ghnotify/pkg/controller/server"
"github.com/m-mizutani/ghnotify/pkg/usecase"
"github.com/stretchr/testify/assert"
)

func TestHealthCheck(t *testing.T) {
srv := server.New(&usecase.Usecase{})

w := httptest.NewRecorder()
r := httptest.NewRequest("GET", "/health", nil)
srv.ServeHTTP(w, r)

assert.Equal(t, 200, w.Code)
}
2 changes: 2 additions & 0 deletions pkg/controller/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ func New(uc *usecase.Usecase) *Server {

r.Post("/webhook/github", serveGitHubWebhook(uc))

r.Get("/health", handleHealthCheckRequest())

return &Server{
uc: uc,
mux: r,
Expand Down

0 comments on commit a8d378d

Please sign in to comment.