From 9504871174848d6c3f47c6ba1d89899d1cd6c7f1 Mon Sep 17 00:00:00 2001 From: Jaime Martinez Date: Wed, 3 Feb 2021 16:51:49 +1100 Subject: 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. --- internal/serving/disk/zip/serving_test.go | 34 +++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'internal/serving/disk/zip') 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: `Found.`, + }, + "accessing without / from disk": { + vfsPath: fileURL, path: "", expectedStatus: http.StatusFound, expectedBody: `Found.`, @@ -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 { -- cgit v1.2.3