added test

This commit is contained in:
Tudor Roman 2018-01-28 17:07:42 +02:00
parent 0906ea946d
commit 2ce4923c5f
No known key found for this signature in database
GPG Key ID: 5AFEDD03CA5A1EA4

View File

@ -16,8 +16,16 @@ import (
"github.com/stretchr/testify/assert"
)
func performRequest(r http.Handler, method, path string) *httptest.ResponseRecorder {
type header struct {
Key string
Value string
}
func performRequest(r http.Handler, method, path string, headers ...header) *httptest.ResponseRecorder {
req, _ := http.NewRequest(method, path, nil)
for _, h := range headers {
req.Header.Add(h.Key, h.Value)
}
w := httptest.NewRecorder()
r.ServeHTTP(w, req)
return w
@ -170,6 +178,13 @@ func TestRouteRedirectTrailingSlash(t *testing.T) {
w = performRequest(router, "PUT", "/path4/")
assert.Equal(t, 200, w.Code)
w = performRequest(router, "GET", "/path2", header{Key: "X-Forwarded-Prefix", Value: "/api"})
assert.Equal(t, "/api/path2/", w.Header().Get("Location"))
assert.Equal(t, 301, w.Code)
w = performRequest(router, "GET", "/path2/", header{Key: "X-Forwarded-Prefix", Value: "/api/"})
assert.Equal(t, 200, w.Code)
router.RedirectTrailingSlash = false
w = performRequest(router, "GET", "/path/")