summaryrefslogtreecommitdiffstats
path: root/routers/api
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2023-09-01 19:26:07 +0800
committerGitHub <noreply@github.com>2023-09-01 11:26:07 +0000
commite8aae43f56fedd6f7b04affd378c2c4ed2af9d78 (patch)
treea9b03cbf3f926f2cd27eb4d3c18126aec1cc7aa9 /routers/api
parentfcb4941d47217f3a369148d98b07e27205f385b8 (diff)
downloadgitea-e8aae43f56fedd6f7b04affd378c2c4ed2af9d78.tar.gz
gitea-e8aae43f56fedd6f7b04affd378c2c4ed2af9d78.zip
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
Diffstat (limited to 'routers/api')
-rw-r--r--routers/api/v1/misc/markup_test.go10
-rw-r--r--routers/api/v1/repo/hook_test.go10
-rw-r--r--routers/api/v1/repo/repo_test.go14
3 files changed, 17 insertions, 17 deletions
diff --git a/routers/api/v1/misc/markup_test.go b/routers/api/v1/misc/markup_test.go
index bab06b3e66..ec8f8f47b7 100644
--- a/routers/api/v1/misc/markup_test.go
+++ b/routers/api/v1/misc/markup_test.go
@@ -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)
diff --git a/routers/api/v1/repo/hook_test.go b/routers/api/v1/repo/hook_test.go
index b43a22cd55..94a71e20ad 100644
--- a/routers/api/v1/repo/hook_test.go
+++ b/routers/api/v1/repo/hook_test.go
@@ -9,7 +9,7 @@ import (
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/models/webhook"
- "code.gitea.io/gitea/modules/test"
+ "code.gitea.io/gitea/modules/contexttest"
"github.com/stretchr/testify/assert"
)
@@ -17,11 +17,11 @@ import (
func TestTestHook(t *testing.T) {
unittest.PrepareTestEnv(t)
- ctx, _ := test.MockAPIContext(t, "user2/repo1/wiki/_pages")
+ ctx, _ := contexttest.MockAPIContext(t, "user2/repo1/wiki/_pages")
ctx.SetParams(":id", "1")
- test.LoadRepo(t, ctx, 1)
- test.LoadRepoCommit(t, ctx)
- test.LoadUser(t, ctx, 2)
+ contexttest.LoadRepo(t, ctx, 1)
+ contexttest.LoadRepoCommit(t, ctx)
+ contexttest.LoadUser(t, ctx, 2)
TestHook(ctx)
assert.EqualValues(t, http.StatusNoContent, ctx.Resp.Status())
diff --git a/routers/api/v1/repo/repo_test.go b/routers/api/v1/repo/repo_test.go
index 7593a87c2c..29e2d1f21d 100644
--- a/routers/api/v1/repo/repo_test.go
+++ b/routers/api/v1/repo/repo_test.go
@@ -9,8 +9,8 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
+ "code.gitea.io/gitea/modules/contexttest"
api "code.gitea.io/gitea/modules/structs"
- "code.gitea.io/gitea/modules/test"
"code.gitea.io/gitea/modules/web"
"github.com/stretchr/testify/assert"
@@ -19,9 +19,9 @@ import (
func TestRepoEdit(t *testing.T) {
unittest.PrepareTestEnv(t)
- ctx, _ := test.MockAPIContext(t, "user2/repo1")
- test.LoadRepo(t, ctx, 1)
- test.LoadUser(t, ctx, 2)
+ ctx, _ := contexttest.MockAPIContext(t, "user2/repo1")
+ contexttest.LoadRepo(t, ctx, 1)
+ contexttest.LoadUser(t, ctx, 2)
ctx.Repo.Owner = ctx.Doer
description := "new description"
website := "http://wwww.newwebsite.com"
@@ -65,9 +65,9 @@ func TestRepoEdit(t *testing.T) {
func TestRepoEditNameChange(t *testing.T) {
unittest.PrepareTestEnv(t)
- ctx, _ := test.MockAPIContext(t, "user2/repo1")
- test.LoadRepo(t, ctx, 1)
- test.LoadUser(t, ctx, 2)
+ ctx, _ := contexttest.MockAPIContext(t, "user2/repo1")
+ contexttest.LoadRepo(t, ctx, 1)
+ contexttest.LoadUser(t, ctx, 2)
ctx.Repo.Owner = ctx.Doer
name := "newname"
opts := api.EditRepoOption{