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:
authorJ. Shuster <joshuagregoryshuster@gmail.com>2017-09-08 11:58:42 +0300
committerNick Thomas <nick@gitlab.com>2017-09-08 11:58:42 +0300
commit0a144bc6055b41fac726fdc6eeaa7150f622bd20 (patch)
tree9ed2a4dbecbd8146245ae8fa609cd9f54d038bf6 /acceptance_test.go
parent0173d4e6b6b17443155d121a9098d0e742b9c4e3 (diff)
Add an artifacts proxy to GitLab Pages
Diffstat (limited to 'acceptance_test.go')
-rw-r--r--acceptance_test.go97
1 files changed, 97 insertions, 0 deletions
diff --git a/acceptance_test.go b/acceptance_test.go
index 8adef2a6..3e575bdf 100644
--- a/acceptance_test.go
+++ b/acceptance_test.go
@@ -2,10 +2,13 @@ package main
import (
"flag"
+ "fmt"
"io/ioutil"
"net/http"
+ "net/http/httptest"
"os"
"testing"
+ "time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -207,3 +210,97 @@ func TestStatusPage(t *testing.T) {
defer rsp.Body.Close()
assert.Equal(t, http.StatusOK, rsp.StatusCode)
}
+
+func TestProxyRequest(t *testing.T) {
+ skipUnlessEnabled(t)
+ content := "<!DOCTYPE html><html><head><title>Title of the document</title></head><body></body></html>"
+ contentLength := int64(len(content))
+ testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ switch r.URL.Path {
+ case "/projects/1/jobs/2/artifacts/delayed_200.html":
+ time.Sleep(2 * time.Second)
+ case "/projects/1/jobs/2/artifacts/200.html":
+ w.Header().Set("Content-Type", "text/html; charset=utf-8")
+ fmt.Fprint(w, content)
+ case "/projects/1/jobs/2/artifacts/500.html":
+ w.Header().Set("Content-Type", "text/html; charset=utf-8")
+ w.WriteHeader(http.StatusInternalServerError)
+ fmt.Fprint(w, content)
+ default:
+ w.Header().Set("Content-Type", "text/html; charset=utf-8")
+ w.WriteHeader(http.StatusNotFound)
+ fmt.Fprint(w, content)
+ }
+ }))
+ defer testServer.Close()
+ cases := []struct {
+ Path string
+ Status int
+ BinaryOption string
+ Content string
+ Length int64
+ CacheControl string
+ ContentType string
+ Description string
+ }{
+ {
+ "200.html",
+ http.StatusOK,
+ "",
+ content,
+ contentLength,
+ "max-age=3600",
+ "text/html; charset=utf-8",
+ "basic proxied request",
+ },
+ {
+ "delayed_200.html",
+ http.StatusBadGateway,
+ "-artifacts-server-timeout=1",
+ "",
+ 0,
+ "",
+ "text/html; charset=utf-8",
+ "502 error while attempting to proxy",
+ },
+ {
+ "404.html",
+ http.StatusNotFound,
+ "",
+ "",
+ 0,
+ "",
+ "text/html; charset=utf-8",
+ "Proxying 404 from server",
+ },
+ {
+ "500.html",
+ http.StatusInternalServerError,
+ "",
+ "",
+ 0,
+ "",
+ "text/html; charset=utf-8",
+ "Proxying 500 from server",
+ },
+ }
+
+ for _, c := range cases {
+ t.Run(fmt.Sprintf("Proxy Request Test: %s", c.Description), func(t *testing.T) {
+ teardown := RunPagesProcess(t, *pagesBinary, listeners, "", "-artifacts-server="+testServer.URL, c.BinaryOption)
+ defer teardown()
+ resp, err := GetPageFromListener(t, httpListener, "artifact~1~2.gitlab-example.com", c.Path)
+ require.NoError(t, err)
+ defer resp.Body.Close()
+ assert.Equal(t, c.Status, resp.StatusCode)
+ assert.Equal(t, c.ContentType, resp.Header.Get("Content-Type"))
+ if !((c.Status == http.StatusBadGateway) || (c.Status == http.StatusNotFound) || (c.Status == http.StatusInternalServerError)) {
+ body, err := ioutil.ReadAll(resp.Body)
+ require.NoError(t, err)
+ assert.Equal(t, c.Content, string(body))
+ assert.Equal(t, c.Length, resp.ContentLength)
+ assert.Equal(t, c.CacheControl, resp.Header.Get("Cache-Control"))
+ }
+ })
+ }
+}