🎨 Formated healthcheck hanlder
This commit is contained in:
parent
1a183bbb67
commit
d5606340a0
|
@ -3,6 +3,8 @@ package http
|
||||||
import (
|
import (
|
||||||
"github.com/fasthttp/router"
|
"github.com/fasthttp/router"
|
||||||
http "github.com/valyala/fasthttp"
|
http "github.com/valyala/fasthttp"
|
||||||
|
|
||||||
|
"source.toby3d.me/website/oauth/internal/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RequestHandler struct{}
|
type RequestHandler struct{}
|
||||||
|
@ -12,9 +14,10 @@ func NewRequestHandler() *RequestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *RequestHandler) Register(r *router.Router) {
|
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)
|
ctx.SetStatusCode(http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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())
|
||||||
|
}
|
Loading…
Reference in New Issue