1
0
Fork 0
forked from forgejo/forgejo

Move web/api context related testing function into a separate package (#26859)

Just like `models/unittest`, the testing helper functions should be in a
separate package: `contexttest`

And complete the TODO:

> // TODO: move this function to other packages, because it depends on
"models" package
This commit is contained in:
wxiaoguang 2023-09-01 19:26:07 +08:00 committed by GitHub
parent fcb4941d47
commit e8aae43f56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 244 additions and 244 deletions

View file

@ -10,10 +10,10 @@ import (
"strings"
"testing"
"code.gitea.io/gitea/modules/contexttest"
"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/test"
"code.gitea.io/gitea/modules/web"
"github.com/stretchr/testify/assert"
@ -34,7 +34,7 @@ func testRenderMarkup(t *testing.T, mode, filePath, text, responseBody string, r
Wiki: true,
FilePath: filePath,
}
ctx, resp := test.MockAPIContext(t, "POST /api/v1/markup")
ctx, resp := contexttest.MockAPIContext(t, "POST /api/v1/markup")
web.SetForm(ctx, &options)
Markup(ctx)
assert.Equal(t, responseBody, resp.Body.String())
@ -50,7 +50,7 @@ func testRenderMarkdown(t *testing.T, mode, text, responseBody string, responseC
Context: Repo,
Wiki: true,
}
ctx, resp := test.MockAPIContext(t, "POST /api/v1/markdown")
ctx, resp := contexttest.MockAPIContext(t, "POST /api/v1/markdown")
web.SetForm(ctx, &options)
Markdown(ctx)
assert.Equal(t, responseBody, resp.Body.String())
@ -162,7 +162,7 @@ func TestAPI_RenderSimple(t *testing.T) {
Text: "",
Context: Repo,
}
ctx, resp := test.MockAPIContext(t, "POST /api/v1/markdown")
ctx, resp := contexttest.MockAPIContext(t, "POST /api/v1/markdown")
for i := 0; i < len(simpleCases); i += 2 {
options.Text = simpleCases[i]
web.SetForm(ctx, &options)
@ -174,7 +174,7 @@ func TestAPI_RenderSimple(t *testing.T) {
func TestAPI_RenderRaw(t *testing.T) {
setting.AppURL = AppURL
ctx, resp := test.MockAPIContext(t, "POST /api/v1/markdown")
ctx, resp := contexttest.MockAPIContext(t, "POST /api/v1/markdown")
for i := 0; i < len(simpleCases); i += 2 {
ctx.Req.Body = io.NopCloser(strings.NewReader(simpleCases[i]))
MarkdownRaw(ctx)