mirror of
https://github.com/go-gitea/gitea
synced 2025-07-31 22:58:35 +00:00
Refactor web package and context package (#25298)
1. The "web" package shouldn't depends on "modules/context" package, instead, let each "web context" register themselves to the "web" package. 2. The old Init/Free doesn't make sense, so simplify it * The ctx in "Init(ctx)" is never used, and shouldn't be used that way * The "Free" is never called and shouldn't be called because the SSPI instance is shared --------- Co-authored-by: Giteabot <teabot@gitea.io>
This commit is contained in:
@@ -41,7 +41,7 @@ func TestCleanUploadName(t *testing.T) {
|
||||
|
||||
func TestGetUniquePatchBranchName(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
ctx := test.MockContext(t, "user2/repo1")
|
||||
ctx, _ := test.MockContext(t, "user2/repo1")
|
||||
ctx.SetParams(":id", "1")
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
test.LoadRepoCommit(t, ctx)
|
||||
@@ -56,7 +56,7 @@ func TestGetUniquePatchBranchName(t *testing.T) {
|
||||
|
||||
func TestGetClosestParentWithFiles(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
ctx := test.MockContext(t, "user2/repo1")
|
||||
ctx, _ := test.MockContext(t, "user2/repo1")
|
||||
ctx.SetParams(":id", "1")
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
test.LoadRepoCommit(t, ctx)
|
||||
|
@@ -32,7 +32,7 @@ func int64SliceToCommaSeparated(a []int64) string {
|
||||
func TestInitializeLabels(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
assert.NoError(t, repository.LoadRepoConfig())
|
||||
ctx := test.MockContext(t, "user2/repo1/labels/initialize")
|
||||
ctx, _ := test.MockContext(t, "user2/repo1/labels/initialize")
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadRepo(t, ctx, 2)
|
||||
web.SetForm(ctx, &forms.InitializeLabelsForm{TemplateName: "Default"})
|
||||
@@ -57,7 +57,7 @@ func TestRetrieveLabels(t *testing.T) {
|
||||
{1, "leastissues", []int64{2, 1}},
|
||||
{2, "", []int64{}},
|
||||
} {
|
||||
ctx := test.MockContext(t, "user/repo/issues")
|
||||
ctx, _ := test.MockContext(t, "user/repo/issues")
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadRepo(t, ctx, testCase.RepoID)
|
||||
ctx.Req.Form.Set("sort", testCase.Sort)
|
||||
@@ -75,7 +75,7 @@ func TestRetrieveLabels(t *testing.T) {
|
||||
|
||||
func TestNewLabel(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
ctx := test.MockContext(t, "user2/repo1/labels/edit")
|
||||
ctx, _ := test.MockContext(t, "user2/repo1/labels/edit")
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
web.SetForm(ctx, &forms.CreateLabelForm{
|
||||
@@ -93,7 +93,7 @@ func TestNewLabel(t *testing.T) {
|
||||
|
||||
func TestUpdateLabel(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
ctx := test.MockContext(t, "user2/repo1/labels/edit")
|
||||
ctx, _ := test.MockContext(t, "user2/repo1/labels/edit")
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
web.SetForm(ctx, &forms.CreateLabelForm{
|
||||
@@ -113,7 +113,7 @@ func TestUpdateLabel(t *testing.T) {
|
||||
|
||||
func TestDeleteLabel(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
ctx := test.MockContext(t, "user2/repo1/labels/delete")
|
||||
ctx, _ := test.MockContext(t, "user2/repo1/labels/delete")
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
ctx.Req.Form.Set("id", "2")
|
||||
@@ -126,7 +126,7 @@ func TestDeleteLabel(t *testing.T) {
|
||||
|
||||
func TestUpdateIssueLabel_Clear(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
ctx := test.MockContext(t, "user2/repo1/issues/labels")
|
||||
ctx, _ := test.MockContext(t, "user2/repo1/issues/labels")
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
ctx.Req.Form.Set("issue_ids", "1,3")
|
||||
@@ -151,7 +151,7 @@ func TestUpdateIssueLabel_Toggle(t *testing.T) {
|
||||
{"toggle", []int64{1, 2}, 2, true},
|
||||
} {
|
||||
unittest.PrepareTestEnv(t)
|
||||
ctx := test.MockContext(t, "user2/repo1/issues/labels")
|
||||
ctx, _ := test.MockContext(t, "user2/repo1/issues/labels")
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
ctx.Req.Form.Set("issue_ids", int64SliceToCommaSeparated(testCase.IssueIDs))
|
||||
|
@@ -14,7 +14,7 @@ import (
|
||||
|
||||
func TestCheckProjectBoardChangePermissions(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
ctx := test.MockContext(t, "user2/repo1/projects/1/2")
|
||||
ctx, _ := test.MockContext(t, "user2/repo1/projects/1/2")
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
ctx.SetParams(":id", "1")
|
||||
|
@@ -47,7 +47,7 @@ func TestNewReleasePost(t *testing.T) {
|
||||
} {
|
||||
unittest.PrepareTestEnv(t)
|
||||
|
||||
ctx := test.MockContext(t, "user2/repo1/releases/new")
|
||||
ctx, _ := test.MockContext(t, "user2/repo1/releases/new")
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
test.LoadGitRepo(t, ctx)
|
||||
@@ -67,7 +67,7 @@ func TestNewReleasePost(t *testing.T) {
|
||||
|
||||
func TestNewReleasesList(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
ctx := test.MockContext(t, "user2/repo-release/releases")
|
||||
ctx, _ := test.MockContext(t, "user2/repo-release/releases")
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadRepo(t, ctx, 57)
|
||||
test.LoadGitRepo(t, ctx)
|
||||
|
@@ -42,7 +42,7 @@ func TestAddReadOnlyDeployKey(t *testing.T) {
|
||||
}
|
||||
unittest.PrepareTestEnv(t)
|
||||
|
||||
ctx := test.MockContext(t, "user2/repo1/settings/keys")
|
||||
ctx, _ := test.MockContext(t, "user2/repo1/settings/keys")
|
||||
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadRepo(t, ctx, 2)
|
||||
@@ -71,7 +71,7 @@ func TestAddReadWriteOnlyDeployKey(t *testing.T) {
|
||||
|
||||
unittest.PrepareTestEnv(t)
|
||||
|
||||
ctx := test.MockContext(t, "user2/repo1/settings/keys")
|
||||
ctx, _ := test.MockContext(t, "user2/repo1/settings/keys")
|
||||
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadRepo(t, ctx, 2)
|
||||
@@ -94,7 +94,7 @@ func TestAddReadWriteOnlyDeployKey(t *testing.T) {
|
||||
|
||||
func TestCollaborationPost(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
ctx := test.MockContext(t, "user2/repo1/issues/labels")
|
||||
ctx, _ := test.MockContext(t, "user2/repo1/issues/labels")
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadUser(t, ctx, 4)
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
@@ -129,7 +129,7 @@ func TestCollaborationPost(t *testing.T) {
|
||||
|
||||
func TestCollaborationPost_InactiveUser(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
ctx := test.MockContext(t, "user2/repo1/issues/labels")
|
||||
ctx, _ := test.MockContext(t, "user2/repo1/issues/labels")
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadUser(t, ctx, 9)
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
@@ -152,7 +152,7 @@ func TestCollaborationPost_InactiveUser(t *testing.T) {
|
||||
|
||||
func TestCollaborationPost_AddCollaboratorTwice(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
ctx := test.MockContext(t, "user2/repo1/issues/labels")
|
||||
ctx, _ := test.MockContext(t, "user2/repo1/issues/labels")
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadUser(t, ctx, 4)
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
@@ -193,7 +193,7 @@ func TestCollaborationPost_AddCollaboratorTwice(t *testing.T) {
|
||||
|
||||
func TestCollaborationPost_NonExistentUser(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
ctx := test.MockContext(t, "user2/repo1/issues/labels")
|
||||
ctx, _ := test.MockContext(t, "user2/repo1/issues/labels")
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
|
||||
@@ -215,7 +215,7 @@ func TestCollaborationPost_NonExistentUser(t *testing.T) {
|
||||
|
||||
func TestAddTeamPost(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
ctx := test.MockContext(t, "org26/repo43")
|
||||
ctx, _ := test.MockContext(t, "org26/repo43")
|
||||
|
||||
ctx.Req.Form.Set("team", "team11")
|
||||
|
||||
@@ -255,7 +255,7 @@ func TestAddTeamPost(t *testing.T) {
|
||||
|
||||
func TestAddTeamPost_NotAllowed(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
ctx := test.MockContext(t, "org26/repo43")
|
||||
ctx, _ := test.MockContext(t, "org26/repo43")
|
||||
|
||||
ctx.Req.Form.Set("team", "team11")
|
||||
|
||||
@@ -295,7 +295,7 @@ func TestAddTeamPost_NotAllowed(t *testing.T) {
|
||||
|
||||
func TestAddTeamPost_AddTeamTwice(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
ctx := test.MockContext(t, "org26/repo43")
|
||||
ctx, _ := test.MockContext(t, "org26/repo43")
|
||||
|
||||
ctx.Req.Form.Set("team", "team11")
|
||||
|
||||
@@ -336,7 +336,7 @@ func TestAddTeamPost_AddTeamTwice(t *testing.T) {
|
||||
|
||||
func TestAddTeamPost_NonExistentTeam(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
ctx := test.MockContext(t, "org26/repo43")
|
||||
ctx, _ := test.MockContext(t, "org26/repo43")
|
||||
|
||||
ctx.Req.Form.Set("team", "team-non-existent")
|
||||
|
||||
@@ -369,7 +369,7 @@ func TestAddTeamPost_NonExistentTeam(t *testing.T) {
|
||||
|
||||
func TestDeleteTeam(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
ctx := test.MockContext(t, "org3/team1/repo3")
|
||||
ctx, _ := test.MockContext(t, "org3/team1/repo3")
|
||||
|
||||
ctx.Req.Form.Set("id", "2")
|
||||
|
||||
|
@@ -78,7 +78,7 @@ func assertPagesMetas(t *testing.T, expectedNames []string, metas interface{}) {
|
||||
func TestWiki(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
|
||||
ctx := test.MockContext(t, "user2/repo1/wiki/?action=_pages")
|
||||
ctx, _ := test.MockContext(t, "user2/repo1/wiki/?action=_pages")
|
||||
ctx.SetParams("*", "Home")
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
Wiki(ctx)
|
||||
@@ -90,7 +90,7 @@ func TestWiki(t *testing.T) {
|
||||
func TestWikiPages(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
|
||||
ctx := test.MockContext(t, "user2/repo1/wiki/?action=_pages")
|
||||
ctx, _ := test.MockContext(t, "user2/repo1/wiki/?action=_pages")
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
WikiPages(ctx)
|
||||
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
|
||||
@@ -100,7 +100,7 @@ func TestWikiPages(t *testing.T) {
|
||||
func TestNewWiki(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
|
||||
ctx := test.MockContext(t, "user2/repo1/wiki/?action=_new")
|
||||
ctx, _ := test.MockContext(t, "user2/repo1/wiki/?action=_new")
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
NewWiki(ctx)
|
||||
@@ -115,7 +115,7 @@ func TestNewWikiPost(t *testing.T) {
|
||||
} {
|
||||
unittest.PrepareTestEnv(t)
|
||||
|
||||
ctx := test.MockContext(t, "user2/repo1/wiki/?action=_new")
|
||||
ctx, _ := test.MockContext(t, "user2/repo1/wiki/?action=_new")
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
web.SetForm(ctx, &forms.NewWikiForm{
|
||||
@@ -133,7 +133,7 @@ func TestNewWikiPost(t *testing.T) {
|
||||
func TestNewWikiPost_ReservedName(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
|
||||
ctx := test.MockContext(t, "user2/repo1/wiki/?action=_new")
|
||||
ctx, _ := test.MockContext(t, "user2/repo1/wiki/?action=_new")
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
web.SetForm(ctx, &forms.NewWikiForm{
|
||||
@@ -150,7 +150,7 @@ func TestNewWikiPost_ReservedName(t *testing.T) {
|
||||
func TestEditWiki(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
|
||||
ctx := test.MockContext(t, "user2/repo1/wiki/Home?action=_edit")
|
||||
ctx, _ := test.MockContext(t, "user2/repo1/wiki/Home?action=_edit")
|
||||
ctx.SetParams("*", "Home")
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
@@ -166,7 +166,7 @@ func TestEditWikiPost(t *testing.T) {
|
||||
"New/<page>",
|
||||
} {
|
||||
unittest.PrepareTestEnv(t)
|
||||
ctx := test.MockContext(t, "user2/repo1/wiki/Home?action=_new")
|
||||
ctx, _ := test.MockContext(t, "user2/repo1/wiki/Home?action=_new")
|
||||
ctx.SetParams("*", "Home")
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
@@ -188,7 +188,7 @@ func TestEditWikiPost(t *testing.T) {
|
||||
func TestDeleteWikiPagePost(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
|
||||
ctx := test.MockContext(t, "user2/repo1/wiki/Home?action=_delete")
|
||||
ctx, _ := test.MockContext(t, "user2/repo1/wiki/Home?action=_delete")
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
DeleteWikiPagePost(ctx)
|
||||
@@ -207,7 +207,7 @@ func TestWikiRaw(t *testing.T) {
|
||||
} {
|
||||
unittest.PrepareTestEnv(t)
|
||||
|
||||
ctx := test.MockContext(t, "user2/repo1/wiki/raw/"+url.PathEscape(filepath))
|
||||
ctx, _ := test.MockContext(t, "user2/repo1/wiki/raw/"+url.PathEscape(filepath))
|
||||
ctx.SetParams("*", filepath)
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
|
Reference in New Issue
Block a user