2021-11-14 21:15:28 +00:00
|
|
|
package http_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/fasthttp/router"
|
|
|
|
http "github.com/valyala/fasthttp"
|
|
|
|
|
2022-03-13 10:58:34 +00:00
|
|
|
delivery "source.toby3d.me/toby3d/auth/internal/health/delivery/http"
|
|
|
|
"source.toby3d.me/toby3d/auth/internal/testing/httptest"
|
2021-11-14 21:15:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestRequestHandler(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
r := router.New()
|
|
|
|
delivery.NewRequestHandler().Register(r)
|
|
|
|
|
2021-12-28 23:08:50 +00:00
|
|
|
client, _, cleanup := httptest.New(t, r.Handler)
|
2021-11-14 21:15:28 +00:00
|
|
|
t.Cleanup(cleanup)
|
|
|
|
|
2022-02-01 19:32:57 +00:00
|
|
|
const requestURL = "https://app.example.com/health"
|
2022-02-01 21:21:07 +00:00
|
|
|
req, resp := httptest.NewRequest(http.MethodGet, requestURL, nil), http.AcquireResponse()
|
2022-02-01 19:32:57 +00:00
|
|
|
|
2022-02-01 21:21:07 +00:00
|
|
|
t.Cleanup(func() {
|
|
|
|
http.ReleaseRequest(req)
|
|
|
|
http.ReleaseResponse(resp)
|
|
|
|
})
|
2021-11-14 21:15:28 +00:00
|
|
|
|
2022-02-01 19:17:22 +00:00
|
|
|
if err := client.Do(req, resp); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2022-02-01 19:32:57 +00:00
|
|
|
if result := resp.StatusCode(); result != http.StatusOK {
|
|
|
|
t.Errorf("GET %s = %d, want %d", requestURL, result, http.StatusOK)
|
|
|
|
}
|
|
|
|
|
|
|
|
const expBody = `{"ok": true}`
|
|
|
|
if result := string(resp.Body()); result != expBody {
|
|
|
|
t.Errorf("GET %s = %s, want %s", requestURL, result, expBody)
|
|
|
|
}
|
2021-11-14 21:15:28 +00:00
|
|
|
}
|