Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2021-09-17 05:40:34 +0300
committerStan Hu <stanhu@gmail.com>2021-09-19 20:52:28 +0300
commit9bef1869a5a3580afb616ca940ed7c23aea47f5f (patch)
treed2f79df444daebcb758647739835169eaefdd4c3 /internal/handlers
parent159460852e41a77b7bb5d201e127f593681c370c (diff)
chore: clean up handler tests to use httptest.NewRequest
Diffstat (limited to 'internal/handlers')
-rw-r--r--internal/handlers/handlers_test.go20
1 files changed, 6 insertions, 14 deletions
diff --git a/internal/handlers/handlers_test.go b/internal/handlers/handlers_test.go
index 62ea3a33..33a0cdb2 100644
--- a/internal/handlers/handlers_test.go
+++ b/internal/handlers/handlers_test.go
@@ -58,9 +58,7 @@ func TestHandleArtifactRequestedReturnsTrue(t *testing.T) {
handlers := New(mockAuth, mockArtifact)
result := httptest.NewRecorder()
- reqURL, err := url.Parse("/something")
- require.NoError(t, err)
- r := &http.Request{URL: reqURL}
+ r := httptest.NewRequest(http.MethodGet, "/something", nil)
require.Equal(t, true, handlers.HandleArtifactRequest("host", result, r))
}
@@ -120,8 +118,7 @@ func TestForbiddenWithTokenIsNotHandled(t *testing.T) {
handlers := New(mockAuth, nil)
w := httptest.NewRecorder()
- reqURL, _ := url.Parse("/")
- r := &http.Request{URL: reqURL}
+ r := httptest.NewRequest(http.MethodGet, "/", nil)
response := &http.Response{StatusCode: tc.StatusCode}
// nolint:bodyclose // TODO investigate https://gitlab.com/gitlab-org/gitlab-pages/-/issues/606
handled := handlers.checkIfLoginRequiredOrInvalidToken(w, r, tc.Token)(response)
@@ -141,8 +138,7 @@ func TestNotFoundWithoutTokenIsNotHandledWhenNotAuthSupport(t *testing.T) {
handlers := New(mockAuth, nil)
w := httptest.NewRecorder()
- reqURL, _ := url.Parse("/")
- r := &http.Request{URL: reqURL}
+ r := httptest.NewRequest(http.MethodGet, "/", nil)
response := &http.Response{StatusCode: http.StatusNotFound}
// nolint:bodyclose // TODO investigate https://gitlab.com/gitlab-org/gitlab-pages/-/issues/606
handled := handlers.checkIfLoginRequiredOrInvalidToken(w, r, "")(response)
@@ -160,8 +156,7 @@ func TestNotFoundWithoutTokenIsHandled(t *testing.T) {
handlers := New(mockAuth, nil)
w := httptest.NewRecorder()
- reqURL, _ := url.Parse("/")
- r := &http.Request{URL: reqURL}
+ r := httptest.NewRequest(http.MethodGet, "/", nil)
response := &http.Response{StatusCode: http.StatusNotFound}
// nolint:bodyclose // TODO investigate https://gitlab.com/gitlab-org/gitlab-pages/-/issues/606
handled := handlers.checkIfLoginRequiredOrInvalidToken(w, r, "")(response)
@@ -179,8 +174,7 @@ func TestInvalidTokenResponseIsHandled(t *testing.T) {
handlers := New(mockAuth, nil)
w := httptest.NewRecorder()
- reqURL, _ := url.Parse("/")
- r := &http.Request{URL: reqURL}
+ r := httptest.NewRequest(http.MethodGet, "/", nil)
response := &http.Response{StatusCode: http.StatusUnauthorized}
// nolint:bodyclose // TODO investigate https://gitlab.com/gitlab-org/gitlab-pages/-/issues/606
handled := handlers.checkIfLoginRequiredOrInvalidToken(w, r, "token")(response)
@@ -203,9 +197,7 @@ func TestHandleArtifactRequestButGetTokenFails(t *testing.T) {
handlers := New(mockAuth, mockArtifact)
result := httptest.NewRecorder()
- reqURL, err := url.Parse("/something")
- require.NoError(t, err)
- r := &http.Request{URL: reqURL}
+ r := httptest.NewRequest(http.MethodGet, "/something", nil)
require.Equal(t, true, handlers.HandleArtifactRequest("host", result, r))
}