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:
authorVladimir Shushlin <vshushlin@gitlab.com>2019-06-03 14:22:03 +0300
committerNick Thomas <nick@gitlab.com>2019-06-03 14:22:03 +0300
commit9df35356572e09dc2c0907113bf64479204e46a9 (patch)
tree70297534cace3ad4c6015df32757690cc9244992 /internal/testhelpers
parent80fa0bb4e200a6b3b9194766dd209de28d1cf08a (diff)
Redirect unknown ACME challenges to the GitLab instance
Diffstat (limited to 'internal/testhelpers')
-rw-r--r--internal/testhelpers/testhelpers.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/internal/testhelpers/testhelpers.go b/internal/testhelpers/testhelpers.go
new file mode 100644
index 00000000..1c3a1eba
--- /dev/null
+++ b/internal/testhelpers/testhelpers.go
@@ -0,0 +1,44 @@
+package testhelpers
+
+import (
+ "mime"
+ "net/http"
+ "net/http/httptest"
+ "net/url"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+)
+
+// AssertHTTP404 asserts handler returns 404 with provided str body
+func AssertHTTP404(t *testing.T, handler http.HandlerFunc, mode, url string, values url.Values, str interface{}) {
+ w := httptest.NewRecorder()
+ req, err := http.NewRequest(mode, url+"?"+values.Encode(), nil)
+ require.NoError(t, err)
+ handler(w, req)
+
+ assert.Equal(t, http.StatusNotFound, w.Code, "HTTP status")
+
+ if str != nil {
+ contentType, _, _ := mime.ParseMediaType(w.Header().Get("Content-Type"))
+ assert.Equal(t, "text/html", contentType, "Content-Type")
+ assert.Contains(t, w.Body.String(), str)
+ }
+}
+
+// AssertRedirectTo asserts that handler redirects to particular URL
+func AssertRedirectTo(t *testing.T, handler http.HandlerFunc, method string,
+ url string, values url.Values, expectedURL string) {
+
+ assert.HTTPRedirect(t, handler, method, url, values)
+
+ recorder := httptest.NewRecorder()
+
+ req, _ := http.NewRequest(method, url, nil)
+ req.URL.RawQuery = values.Encode()
+
+ handler(recorder, req)
+
+ assert.Equal(t, expectedURL, recorder.Header().Get("Location"))
+}