forked from forgejo/forgejo
Unit tests for routers/repo/issue_label (#3198)
This commit is contained in:
parent
bde0409433
commit
befa7445d2
15 changed files with 231 additions and 42 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue