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>2020-09-09 09:23:02 +0300
committerJaime Martinez <jmartinez@gitlab.com>2020-09-24 03:22:45 +0300
commit3e20c84456ec3194de8a35af3cd287a37c006549 (patch)
tree537e905021f4803bbb67c570136a0c0895ed1424 /internal/serving
parent7802bb75e8edafe05855fcbdb72aeea7bb906ae7 (diff)
Rebase from base branch
Add vfs.VFS implementation for zip Fix build errors Clean zip vfs Add tests for Root Add zip serving metric Return a zip.Instance() when source == zip Add simple acceptance test for zip serving Use correct contents No need to start testServer in go routine
Diffstat (limited to 'internal/serving')
-rw-r--r--internal/serving/disk/local/serving.go3
-rw-r--r--internal/serving/disk/serving.go7
-rw-r--r--internal/serving/disk/zip/serving.go17
-rw-r--r--internal/serving/disk/zip/serving_test.go59
4 files changed, 82 insertions, 4 deletions
diff --git a/internal/serving/disk/local/serving.go b/internal/serving/disk/local/serving.go
index 230a71da..d4a882bc 100644
--- a/internal/serving/disk/local/serving.go
+++ b/internal/serving/disk/local/serving.go
@@ -5,9 +5,10 @@ import (
"gitlab.com/gitlab-org/gitlab-pages/internal/serving/disk"
"gitlab.com/gitlab-org/gitlab-pages/internal/vfs"
"gitlab.com/gitlab-org/gitlab-pages/internal/vfs/local"
+ "gitlab.com/gitlab-org/gitlab-pages/metrics"
)
-var instance = disk.New(vfs.Instrumented(&local.VFS{}, "local"))
+var instance = disk.New(vfs.Instrumented(&local.VFS{}, "local"), metrics.DiskServingFileSize)
// Instance returns a serving instance that is capable of reading files
// from the disk
diff --git a/internal/serving/disk/serving.go b/internal/serving/disk/serving.go
index bb9b40d2..94ea3f23 100644
--- a/internal/serving/disk/serving.go
+++ b/internal/serving/disk/serving.go
@@ -3,10 +3,11 @@ package disk
import (
"os"
+ "github.com/prometheus/client_golang/prometheus"
+
"gitlab.com/gitlab-org/gitlab-pages/internal/httperrors"
"gitlab.com/gitlab-org/gitlab-pages/internal/serving"
"gitlab.com/gitlab-org/gitlab-pages/internal/vfs"
- "gitlab.com/gitlab-org/gitlab-pages/metrics"
)
// Disk describes a disk access serving
@@ -42,10 +43,10 @@ func (s *Disk) ServeNotFoundHTTP(h serving.Handler) {
// New returns a serving instance that is capable of reading files
// from the VFS
-func New(vfs vfs.VFS) serving.Serving {
+func New(vfs vfs.VFS, fileSizeMetric prometheus.Histogram) serving.Serving {
return &Disk{
reader: Reader{
- fileSizeMetric: metrics.DiskServingFileSize,
+ fileSizeMetric: fileSizeMetric,
vfs: vfs,
},
}
diff --git a/internal/serving/disk/zip/serving.go b/internal/serving/disk/zip/serving.go
new file mode 100644
index 00000000..42cc8f0c
--- /dev/null
+++ b/internal/serving/disk/zip/serving.go
@@ -0,0 +1,17 @@
+package zip
+
+import (
+ "gitlab.com/gitlab-org/gitlab-pages/internal/serving"
+ "gitlab.com/gitlab-org/gitlab-pages/internal/serving/disk"
+ "gitlab.com/gitlab-org/gitlab-pages/internal/vfs"
+ "gitlab.com/gitlab-org/gitlab-pages/internal/vfs/zip"
+ "gitlab.com/gitlab-org/gitlab-pages/metrics"
+)
+
+var instance = disk.New(vfs.Instrumented(zip.New(), "zip"), metrics.ZipServingFileSize)
+
+// Instance returns a serving instance that is capable of reading files
+// from a zip archives opened from a URL, most likely stored in object storage
+func Instance() serving.Serving {
+ return instance
+}
diff --git a/internal/serving/disk/zip/serving_test.go b/internal/serving/disk/zip/serving_test.go
new file mode 100644
index 00000000..14fdabdf
--- /dev/null
+++ b/internal/serving/disk/zip/serving_test.go
@@ -0,0 +1,59 @@
+package zip
+
+import (
+ "io/ioutil"
+ "net/http"
+ "net/http/httptest"
+ "testing"
+
+ "github.com/stretchr/testify/require"
+
+ "gitlab.com/gitlab-org/gitlab-pages/internal/serving"
+ "gitlab.com/gitlab-org/gitlab-pages/internal/testhelpers"
+)
+
+func TestZip_ServeFileHTTP(t *testing.T) {
+ testServerURL, cleanup := newZipFileServerURL(t, "group/zip.gitlab.io/public.zip")
+ defer cleanup()
+
+ s := Instance()
+ w := httptest.NewRecorder()
+ r := httptest.NewRequest("GET", "http://zip.gitlab.io/zip/index.html", nil)
+ handler := serving.Handler{
+ Writer: w,
+ Request: r,
+ LookupPath: &serving.LookupPath{
+ Prefix: "",
+ Path: testServerURL + "/public.zip",
+ },
+ SubPath: "/index.html",
+ }
+
+ require.True(t, s.ServeFileHTTP(handler))
+
+ resp := w.Result()
+ defer resp.Body.Close()
+
+ require.Equal(t, http.StatusOK, resp.StatusCode)
+ body, err := ioutil.ReadAll(resp.Body)
+ require.NoError(t, err)
+
+ require.Contains(t, string(body), "zip.gitlab.io/project/index.html\n")
+}
+
+var chdirSet = false
+
+func newZipFileServerURL(t *testing.T, zipFilePath string) (string, func()) {
+ t.Helper()
+
+ chdir := testhelpers.ChdirInPath(t, "../../../../shared/pages", &chdirSet)
+
+ testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ http.ServeFile(w, r, zipFilePath)
+ }))
+
+ return testServer.URL, func() {
+ chdir()
+ testServer.Close()
+ }
+}