diff options
author | feistel <6742251-feistel@users.noreply.gitlab.com> | 2021-12-08 03:32:14 +0300 |
---|---|---|
committer | feistel <6742251-feistel@users.noreply.gitlab.com> | 2021-12-08 03:32:14 +0300 |
commit | 22f04dc1ae0869616a6751dc3c9c28740e09d1bb (patch) | |
tree | cc928a07e29cfeb513c2cd489c6ca28d88e71a49 /internal/serving | |
parent | 2828e3b72a0a786736c2d6bcd5f591d5034e2754 (diff) |
test: add sha256 to mocked lookups and fix tests
Diffstat (limited to 'internal/serving')
-rw-r--r-- | internal/serving/disk/zip/serving_test.go | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/internal/serving/disk/zip/serving_test.go b/internal/serving/disk/zip/serving_test.go index f16bbada..86f38df2 100644 --- a/internal/serving/disk/zip/serving_test.go +++ b/internal/serving/disk/zip/serving_test.go @@ -1,6 +1,7 @@ package zip import ( + "crypto/sha256" "io" "net/http" "net/http/httptest" @@ -27,7 +28,6 @@ func TestZip_ServeFileHTTP(t *testing.T) { tests := map[string]struct { vfsPath string - sha256 string path string expectedStatus int expectedBody string @@ -35,21 +35,18 @@ func TestZip_ServeFileHTTP(t *testing.T) { }{ "accessing /index.html": { vfsPath: httpURL, - sha256: "d6b318b399cfe9a1c8483e49847ee49a2676d8cfd6df57ec64d971ad03640a75", path: "/index.html", expectedStatus: http.StatusOK, expectedBody: "zip.gitlab.io/project/index.html\n", }, "accessing /index.html from disk": { vfsPath: fileURL, - sha256: "15c5438164ec67bb2225f68d7d7a2e0b608035264e5275b7e3302641aa25a528", path: "/index.html", expectedStatus: http.StatusOK, expectedBody: "zip.gitlab.io/project/index.html\n", }, "accessing /": { vfsPath: httpURL, - sha256: "d6b318b399cfe9a1c8483e49847ee49a2676d8cfd6df57ec64d971ad03640a75", path: "/", expectedStatus: http.StatusOK, expectedBody: "zip.gitlab.io/project/index.html\n", @@ -72,29 +69,24 @@ func TestZip_ServeFileHTTP(t *testing.T) { }, "accessing / from disk": { vfsPath: fileURL, - sha256: "15c5438164ec67bb2225f68d7d7a2e0b608035264e5275b7e3302641aa25a528", path: "/", expectedStatus: http.StatusOK, expectedBody: "zip.gitlab.io/project/index.html\n", }, "accessing without /": { vfsPath: httpURL, - sha256: "d6b318b399cfe9a1c8483e49847ee49a2676d8cfd6df57ec64d971ad03640a75", path: "", expectedStatus: http.StatusFound, expectedBody: `<a href="//zip.gitlab.io/zip/">Found</a>.`, }, "accessing without / from disk": { vfsPath: fileURL, - sha256: "15c5438164ec67bb2225f68d7d7a2e0b608035264e5275b7e3302641aa25a528", path: "", expectedStatus: http.StatusFound, expectedBody: `<a href="//zip.gitlab.io/zip/">Found</a>.`, }, "accessing archive that is 404": { vfsPath: testServerURL + "/invalid.zip", - // the sha is needed or we would get a 500 - sha256: "foo", path: "/index.html", // we expect the status to not be set expectedStatus: 0, @@ -129,17 +121,20 @@ func TestZip_ServeFileHTTP(t *testing.T) { t.Run(name, func(t *testing.T) { w := httptest.NewRecorder() w.Code = 0 // ensure that code is not set, and it is being set by handler - r := httptest.NewRequest("GET", "http://zip.gitlab.io/zip"+test.path, nil) + r := httptest.NewRequest(http.MethodGet, "http://zip.gitlab.io/zip"+test.path, nil) r.Header = test.extraHeaders + sha := sha256.Sum256([]byte(test.vfsPath)) + etag := string(sha[:]) + handler := serving.Handler{ Writer: w, Request: r, LookupPath: &serving.LookupPath{ Prefix: "/zip/", Path: test.vfsPath, - SHA256: test.sha256, + SHA256: etag, }, SubPath: test.path, } |