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:
authorJaime Martinez <jmartinez@gitlab.com>2021-02-03 08:51:49 +0300
committerJaime Martinez <jmartinez@gitlab.com>2021-02-08 02:52:07 +0300
commit9504871174848d6c3f47c6ba1d89899d1cd6c7f1 (patch)
tree05efc1f52a20e2691cdd95289a97396e59b09730 /internal/serving
parent4f07314b781e387183b29dff7d7ad62b9c111f26 (diff)
Refactor http client usage in httprage
Moves the http.Client initialization inside the `httprange` package to the zip VFS. This makes the type `Resource` depend on an http.Client that needs to be passed on initialization. It also makes the zip VFS initialize the client. It's possible to reconfigure it to register a file protocol by calling vfs.Reconfigure explicitly.
Diffstat (limited to 'internal/serving')
-rw-r--r--internal/serving/disk/zip/serving_test.go34
1 files changed, 30 insertions, 4 deletions
diff --git a/internal/serving/disk/zip/serving_test.go b/internal/serving/disk/zip/serving_test.go
index e64a761a..bfa9e155 100644
--- a/internal/serving/disk/zip/serving_test.go
+++ b/internal/serving/disk/zip/serving_test.go
@@ -4,6 +4,7 @@ import (
"io/ioutil"
"net/http"
"net/http/httptest"
+ "os"
"testing"
"time"
@@ -18,6 +19,12 @@ func TestZip_ServeFileHTTP(t *testing.T) {
testServerURL, cleanup := newZipFileServerURL(t, "group/zip.gitlab.io/public-without-dirs.zip")
defer cleanup()
+ wd, err := os.Getwd()
+ require.NoError(t, err)
+
+ httpURL := testServerURL + "/public.zip"
+ fileURL := "file://" + wd + "/group/zip.gitlab.io/public-without-dirs.zip"
+
tests := map[string]struct {
vfsPath string
path string
@@ -25,19 +32,37 @@ func TestZip_ServeFileHTTP(t *testing.T) {
expectedBody string
}{
"accessing /index.html": {
- vfsPath: testServerURL + "/public.zip",
+ vfsPath: httpURL,
+ path: "/index.html",
+ expectedStatus: http.StatusOK,
+ expectedBody: "zip.gitlab.io/project/index.html\n",
+ },
+ "accessing /index.html from disk": {
+ vfsPath: fileURL,
path: "/index.html",
expectedStatus: http.StatusOK,
expectedBody: "zip.gitlab.io/project/index.html\n",
},
"accessing /": {
- vfsPath: testServerURL + "/public.zip",
+ vfsPath: httpURL,
+ path: "/",
+ expectedStatus: http.StatusOK,
+ expectedBody: "zip.gitlab.io/project/index.html\n",
+ },
+ "accessing / from disk": {
+ vfsPath: fileURL,
path: "/",
expectedStatus: http.StatusOK,
expectedBody: "zip.gitlab.io/project/index.html\n",
},
"accessing without /": {
- vfsPath: testServerURL + "/public.zip",
+ vfsPath: httpURL,
+ path: "",
+ expectedStatus: http.StatusFound,
+ expectedBody: `<a href="//zip.gitlab.io/zip/">Found</a>.`,
+ },
+ "accessing without / from disk": {
+ vfsPath: fileURL,
path: "",
expectedStatus: http.StatusFound,
expectedBody: `<a href="//zip.gitlab.io/zip/">Found</a>.`,
@@ -61,11 +86,12 @@ func TestZip_ServeFileHTTP(t *testing.T) {
CleanupInterval: 5 * time.Second,
RefreshInterval: 5 * time.Second,
OpenTimeout: 5 * time.Second,
+ AllowedPaths: []string{wd},
},
}
s := Instance()
- err := s.Reconfigure(cfg)
+ err = s.Reconfigure(cfg)
require.NoError(t, err)
for name, test := range tests {