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:
authoryigithankardas <root>2022-02-18 04:04:13 +0300
committeryigithankardas <root>2022-02-18 04:04:13 +0300
commit5c08f7dd4f4e386652ce70341e6eabad3b0ffbb3 (patch)
tree645f8b46f19986dff5ce4e17f8e99514a0c4beab
parente901d0794f96d525ce30f291a3a32f8936917a36 (diff)
refactor: use testhelpers.Close()
-rw-r--r--internal/auth/auth_test.go11
-rw-r--r--internal/httpfs/http_fs_test.go3
-rw-r--r--internal/httptransport/metered_round_tripper_test.go3
-rw-r--r--internal/serving/disk/local/serving_test.go2
-rw-r--r--internal/serving/disk/zip/serving_test.go2
-rw-r--r--internal/urilimiter/urilimiter_test.go3
6 files changed, 14 insertions, 10 deletions
diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go
index 47e424c1..61b4e88a 100644
--- a/internal/auth/auth_test.go
+++ b/internal/auth/auth_test.go
@@ -17,6 +17,7 @@ import (
"gitlab.com/gitlab-org/gitlab-pages/internal/request"
"gitlab.com/gitlab-org/gitlab-pages/internal/source/mock"
+ "gitlab.com/gitlab-org/gitlab-pages/internal/testhelpers"
)
func createTestAuth(t *testing.T, internalServer string, publicServer string) *Auth {
@@ -68,7 +69,7 @@ func setSessionValues(t *testing.T, r *http.Request, store sessions.Store, value
session.Save(tmpRequest, result)
res := result.Result()
- defer res.Body.Close()
+ testhelpers.Close(t, res.Body)
for _, cookie := range res.Cookies() {
r.AddCookie(cookie)
@@ -232,7 +233,7 @@ func testTryAuthenticateWithCodeAndState(t *testing.T, https bool) {
require.True(t, auth.TryAuthenticate(result, r, mockSource))
res := result.Result()
- defer res.Body.Close()
+ testhelpers.Close(t, res.Body)
require.Equal(t, http.StatusFound, result.Code)
require.Equal(t, "https://pages.gitlab-example.com/project/", result.Header().Get("Location"))
@@ -318,7 +319,7 @@ func TestCheckAuthenticationWhenNoAccess(t *testing.T) {
contentServed := auth.CheckAuthentication(w, r, &domainMock{projectID: 1000, notFoundContent: "Generic 404"})
require.True(t, contentServed)
res := w.Result()
- defer res.Body.Close()
+ testhelpers.Close(t, res.Body)
require.Equal(t, http.StatusNotFound, res.StatusCode)
@@ -493,11 +494,11 @@ func TestCheckResponseForInvalidTokenWhenInvalidToken(t *testing.T) {
r := &http.Request{URL: reqURL, Host: "pages.gitlab-example.com", RequestURI: "/test"}
resp := &http.Response{StatusCode: http.StatusUnauthorized, Body: io.NopCloser(bytes.NewReader([]byte("{\"error\":\"invalid_token\"}")))}
- defer resp.Body.Close()
+ testhelpers.Close(t, resp.Body)
require.True(t, auth.CheckResponseForInvalidToken(result, r, resp))
res := result.Result()
- defer res.Body.Close()
+ testhelpers.Close(t, res.Body)
require.Equal(t, http.StatusFound, res.StatusCode)
require.Equal(t, "http://pages.gitlab-example.com/test", result.Header().Get("Location"))
}
diff --git a/internal/httpfs/http_fs_test.go b/internal/httpfs/http_fs_test.go
index 991c6017..25003726 100644
--- a/internal/httpfs/http_fs_test.go
+++ b/internal/httpfs/http_fs_test.go
@@ -11,6 +11,7 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitlab-pages/internal/httptransport"
+ "gitlab.com/gitlab-org/gitlab-pages/internal/testhelpers"
)
func TestFSOpen(t *testing.T) {
@@ -161,7 +162,7 @@ func TestFileSystemPathCanServeHTTP(t *testing.T) {
res, err := client.Do(req)
require.NoError(t, err)
- defer res.Body.Close()
+ testhelpers.Close(t, res.Body)
require.Equal(t, test.expectedStatusCode, res.StatusCode)
content, err := io.ReadAll(res.Body)
diff --git a/internal/httptransport/metered_round_tripper_test.go b/internal/httptransport/metered_round_tripper_test.go
index 2b126760..8a298e20 100644
--- a/internal/httptransport/metered_round_tripper_test.go
+++ b/internal/httptransport/metered_round_tripper_test.go
@@ -10,6 +10,7 @@ import (
"github.com/prometheus/client_golang/prometheus/testutil"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitlab-pages/internal/testhelpers"
)
func TestReconfigureMeteredRoundTripper(t *testing.T) {
@@ -23,7 +24,7 @@ func TestReconfigureMeteredRoundTripper(t *testing.T) {
res, err := mrt.RoundTrip(r)
require.NoError(t, err)
- defer res.Body.Close()
+ testhelpers.Close(t, res.Body)
require.Equal(t, http.StatusOK, res.StatusCode)
body, err := io.ReadAll(res.Body)
diff --git a/internal/serving/disk/local/serving_test.go b/internal/serving/disk/local/serving_test.go
index 8352bfc9..dbb14138 100644
--- a/internal/serving/disk/local/serving_test.go
+++ b/internal/serving/disk/local/serving_test.go
@@ -79,7 +79,7 @@ func TestDisk_ServeFileHTTP(t *testing.T) {
require.True(t, s.ServeFileHTTP(handler))
resp := w.Result()
- defer resp.Body.Close()
+ testhelpers.Close(t, resp.Body)
require.Equal(t, test.expectedStatus, resp.StatusCode)
body, err := io.ReadAll(resp.Body)
diff --git a/internal/serving/disk/zip/serving_test.go b/internal/serving/disk/zip/serving_test.go
index 2b603b5d..c3b18f2b 100644
--- a/internal/serving/disk/zip/serving_test.go
+++ b/internal/serving/disk/zip/serving_test.go
@@ -209,7 +209,7 @@ func TestZip_ServeFileHTTP(t *testing.T) {
require.True(t, s.ServeFileHTTP(handler))
resp := w.Result()
- defer resp.Body.Close()
+ testhelpers.Close(t, resp.Body)
require.Equal(t, test.expectedStatus, resp.StatusCode)
body, err := io.ReadAll(resp.Body)
diff --git a/internal/urilimiter/urilimiter_test.go b/internal/urilimiter/urilimiter_test.go
index 0ac89ea0..a314ec91 100644
--- a/internal/urilimiter/urilimiter_test.go
+++ b/internal/urilimiter/urilimiter_test.go
@@ -8,6 +8,7 @@ import (
"testing"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitlab-pages/internal/testhelpers"
)
func TestNewMiddleware(t *testing.T) {
@@ -56,7 +57,7 @@ func TestNewMiddleware(t *testing.T) {
middleware.ServeHTTP(ww, rr)
res := ww.Result()
- defer res.Body.Close()
+ testhelpers.Close(t, res.Body)
require.Equal(t, tt.expectedStatus, res.StatusCode)
if tt.expectedStatus == http.StatusOK {