summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/test/context_tests.go23
-rw-r--r--modules/test/utils.go14
2 files changed, 21 insertions, 16 deletions
diff --git a/modules/test/context_tests.go b/modules/test/context_tests.go
index 11f3d83b83..bd5ea3fd38 100644
--- a/modules/test/context_tests.go
+++ b/modules/test/context_tests.go
@@ -16,6 +16,7 @@ import (
"github.com/go-macaron/session"
"github.com/stretchr/testify/assert"
"gopkg.in/macaron.v1"
+ "net/http/httptest"
)
// MockContext mock context for unit tests
@@ -44,6 +45,7 @@ func MockContext(t *testing.T, path string) *context.Context {
func LoadRepo(t *testing.T, ctx *context.Context, repoID int64) {
ctx.Repo = &context.Repository{}
ctx.Repo.Repository = models.AssertExistsAndLoadBean(t, &models.Repository{ID: repoID}).(*models.Repository)
+ ctx.Repo.RepoLink = ctx.Repo.Repository.Link()
}
// LoadUser load a user into a test context.
@@ -71,32 +73,21 @@ func (l mockLocale) Tr(s string, _ ...interface{}) string {
}
type mockResponseWriter struct {
- status int
- size int
-}
-
-func (rw *mockResponseWriter) Header() http.Header {
- return map[string][]string{}
+ httptest.ResponseRecorder
+ size int
}
func (rw *mockResponseWriter) Write(b []byte) (int, error) {
rw.size += len(b)
- return len(b), nil
-}
-
-func (rw *mockResponseWriter) WriteHeader(status int) {
- rw.status = status
-}
-
-func (rw *mockResponseWriter) Flush() {
+ return rw.ResponseRecorder.Write(b)
}
func (rw *mockResponseWriter) Status() int {
- return rw.status
+ return rw.ResponseRecorder.Code
}
func (rw *mockResponseWriter) Written() bool {
- return rw.status > 0
+ return rw.ResponseRecorder.Code > 0
}
func (rw *mockResponseWriter) Size() int {
diff --git a/modules/test/utils.go b/modules/test/utils.go
new file mode 100644
index 0000000000..ed1628ab47
--- /dev/null
+++ b/modules/test/utils.go
@@ -0,0 +1,14 @@
+// Copyright 2017 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package test
+
+import (
+ "net/http"
+)
+
+// RedirectURL returns the redirect URL of a http response.
+func RedirectURL(resp http.ResponseWriter) string {
+ return resp.Header().Get("Location")
+}