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:
Diffstat (limited to 'internal/serving/disk/zip/serving_test.go')
-rw-r--r--internal/serving/disk/zip/serving_test.go32
1 files changed, 30 insertions, 2 deletions
diff --git a/internal/serving/disk/zip/serving_test.go b/internal/serving/disk/zip/serving_test.go
index e95432ae..bca2ae51 100644
--- a/internal/serving/disk/zip/serving_test.go
+++ b/internal/serving/disk/zip/serving_test.go
@@ -17,25 +17,40 @@ func TestZip_ServeFileHTTP(t *testing.T) {
defer cleanup()
tests := map[string]struct {
+ vfsPath string
path string
expectedStatus int
expectedBody string
}{
"accessing /index.html": {
+ vfsPath: testServerURL + "/public.zip",
path: "/index.html",
expectedStatus: http.StatusOK,
expectedBody: "zip.gitlab.io/project/index.html\n",
},
"accessing /": {
+ vfsPath: testServerURL + "/public.zip",
path: "/",
expectedStatus: http.StatusOK,
expectedBody: "zip.gitlab.io/project/index.html\n",
},
"accessing without /": {
+ vfsPath: testServerURL + "/public.zip",
path: "",
expectedStatus: http.StatusFound,
expectedBody: `<a href="//zip.gitlab.io/zip/">Found</a>.`,
},
+ "accessing archive that is 404": {
+ vfsPath: testServerURL + "/invalid.zip",
+ path: "/index.html",
+ // we expect the status to not be set
+ expectedStatus: 0,
+ },
+ "accessing archive that is 500": {
+ vfsPath: testServerURL + "/500",
+ path: "/index.html",
+ expectedStatus: http.StatusInternalServerError,
+ },
}
s := Instance()
@@ -43,6 +58,7 @@ func TestZip_ServeFileHTTP(t *testing.T) {
for name, test := range tests {
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)
handler := serving.Handler{
@@ -50,11 +66,17 @@ func TestZip_ServeFileHTTP(t *testing.T) {
Request: r,
LookupPath: &serving.LookupPath{
Prefix: "/zip/",
- Path: testServerURL + "/public.zip",
+ Path: test.vfsPath,
},
SubPath: test.path,
}
+ if test.expectedStatus == 0 {
+ require.False(t, s.ServeFileHTTP(handler))
+ require.Zero(t, w.Code, "we expect status to not be set")
+ return
+ }
+
require.True(t, s.ServeFileHTTP(handler))
resp := w.Result()
@@ -76,9 +98,15 @@ func newZipFileServerURL(t *testing.T, zipFilePath string) (string, func()) {
chdir := testhelpers.ChdirInPath(t, "../../../../shared/pages", &chdirSet)
- testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ m := http.NewServeMux()
+ m.HandleFunc("/public.zip", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, zipFilePath)
}))
+ m.HandleFunc("/500", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.WriteHeader(http.StatusInternalServerError)
+ }))
+
+ testServer := httptest.NewServer(m)
return testServer.URL, func() {
chdir()