diff options
Diffstat (limited to 'internal/serving/disk/zip')
-rw-r--r-- | internal/serving/disk/zip/serving_test.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/internal/serving/disk/zip/serving_test.go b/internal/serving/disk/zip/serving_test.go index ed18e6c3..f16bbada 100644 --- a/internal/serving/disk/zip/serving_test.go +++ b/internal/serving/disk/zip/serving_test.go @@ -31,6 +31,7 @@ func TestZip_ServeFileHTTP(t *testing.T) { path string expectedStatus int expectedBody string + extraHeaders http.Header }{ "accessing /index.html": { vfsPath: httpURL, @@ -53,6 +54,22 @@ func TestZip_ServeFileHTTP(t *testing.T) { expectedStatus: http.StatusOK, expectedBody: "zip.gitlab.io/project/index.html\n", }, + "accessing / If-Modified-Since": { + vfsPath: httpURL, + path: "/", + expectedStatus: http.StatusNotModified, + extraHeaders: http.Header{ + "If-Modified-Since": {time.Now().Format(http.TimeFormat)}, + }, + }, + "accessing / If-Unmodified-Since": { + vfsPath: httpURL, + path: "/", + expectedStatus: http.StatusPreconditionFailed, + extraHeaders: http.Header{ + "If-Unmodified-Since": {time.Now().AddDate(-10, 0, 0).Format(http.TimeFormat)}, + }, + }, "accessing / from disk": { vfsPath: fileURL, sha256: "15c5438164ec67bb2225f68d7d7a2e0b608035264e5275b7e3302641aa25a528", @@ -114,6 +131,8 @@ func TestZip_ServeFileHTTP(t *testing.T) { 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.Header = test.extraHeaders + handler := serving.Handler{ Writer: w, Request: r, @@ -140,6 +159,10 @@ func TestZip_ServeFileHTTP(t *testing.T) { body, err := io.ReadAll(resp.Body) require.NoError(t, err) + if test.expectedStatus == http.StatusOK { + require.NotEmpty(t, resp.Header.Get("Last-Modified")) + } + require.Contains(t, string(body), test.expectedBody) }) } |