diff options
author | Ethan Koenig <ethantkoenig@gmail.com> | 2017-12-15 13:11:02 -0800 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2017-12-15 23:11:02 +0200 |
commit | befa7445d254cc88662015222c85ccd4c96b9a10 (patch) | |
tree | d9d7bc81d0eb05c026e8b6688871b38695d5af00 /modules | |
parent | bde0409433531b024e30cf1a4d3e44051631ed85 (diff) | |
download | gitea-befa7445d254cc88662015222c85ccd4c96b9a10.tar.gz gitea-befa7445d254cc88662015222c85ccd4c96b9a10.zip |
Unit tests for routers/repo/issue_label (#3198)
Diffstat (limited to 'modules')
-rw-r--r-- | modules/test/context_tests.go | 23 | ||||
-rw-r--r-- | modules/test/utils.go | 14 |
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") +} |