auth/internal/health/delivery/http/health_http_test.go

36 lines
717 B
Go
Raw Normal View History

2021-11-14 21:15:28 +00:00
package http_test
import (
2023-01-02 00:11:47 +00:00
"io"
"net/http"
2023-01-02 00:11:47 +00:00
"net/http/httptest"
2021-11-14 21:15:28 +00:00
"testing"
delivery "source.toby3d.me/toby3d/auth/internal/health/delivery/http"
2021-11-14 21:15:28 +00:00
)
func TestRequestHandler(t *testing.T) {
t.Parallel()
2023-01-02 00:11:47 +00:00
req := httptest.NewRequest(http.MethodGet, "https://example.com/health", nil)
w := httptest.NewRecorder()
delivery.NewHandler().
ServeHTTP(w, req)
2021-11-14 21:15:28 +00:00
2023-01-02 00:11:47 +00:00
resp := w.Result()
2021-11-14 21:15:28 +00:00
2023-01-02 00:11:47 +00:00
if exp := http.StatusOK; resp.StatusCode != exp {
t.Errorf("%s %s = %d, want %d", req.Method, req.RequestURI, resp.StatusCode, exp)
}
2023-01-02 00:11:47 +00:00
body, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}
2023-01-02 00:11:47 +00:00
if exp := `👌`; string(body) != exp {
t.Errorf("%s %s = '%s', want '%s'", req.Method, req.RequestURI, body, exp)
}
2021-11-14 21:15:28 +00:00
}