🎨 Formated healthcheck hanlder

This commit is contained in:
Maxim Lebedev 2021-11-15 02:15:28 +05:00
parent 1a183bbb67
commit d5606340a0
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
2 changed files with 39 additions and 2 deletions

View File

@ -3,6 +3,8 @@ package http
import (
"github.com/fasthttp/router"
http "github.com/valyala/fasthttp"
"source.toby3d.me/website/oauth/internal/common"
)
type RequestHandler struct{}
@ -12,9 +14,10 @@ func NewRequestHandler() *RequestHandler {
}
func (h *RequestHandler) Register(r *router.Router) {
r.GET("/health", h.Read)
r.GET("/health", h.RequestHandler)
}
func (h *RequestHandler) Read(ctx *http.RequestCtx) {
func (h *RequestHandler) RequestHandler(ctx *http.RequestCtx) {
ctx.SetContentType(common.MIMETextPlainCharsetUTF8)
ctx.SetStatusCode(http.StatusOK)
}

View File

@ -0,0 +1,34 @@
package http_test
import (
"testing"
"github.com/fasthttp/router"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
http "github.com/valyala/fasthttp"
delivery "source.toby3d.me/website/oauth/internal/health/delivery/http"
"source.toby3d.me/website/oauth/internal/util"
)
func TestRequestHandler(t *testing.T) {
t.Parallel()
r := router.New()
delivery.NewRequestHandler().Register(r)
client, _, cleanup := util.TestServe(t, r.Handler)
t.Cleanup(cleanup)
req := http.AcquireRequest()
defer http.ReleaseRequest(req)
req.Header.SetMethod(http.MethodGet)
req.SetRequestURI("https://app.example.com/health")
resp := http.AcquireResponse()
defer http.ReleaseResponse(resp)
require.NoError(t, client.Do(req, resp))
assert.Equal(t, http.StatusOK, resp.StatusCode())
}