diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2021-11-12 22:36:47 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-12 22:36:47 +0800 |
commit | df64fa486555de6f403a795fd16c2e9e1d59e535 (patch) | |
tree | b899e9b9e5d57409b1bf0e3afbd606b6a3900235 /routers/web/repo | |
parent | 7f802631c54d2e91301158380b273b872d62bd80 (diff) | |
download | gitea-df64fa486555de6f403a795fd16c2e9e1d59e535.tar.gz gitea-df64fa486555de6f403a795fd16c2e9e1d59e535.zip |
Decouple unit test code from business code (#17623)
Diffstat (limited to 'routers/web/repo')
-rw-r--r-- | routers/web/repo/editor_test.go | 8 | ||||
-rw-r--r-- | routers/web/repo/issue_label_test.go | 15 | ||||
-rw-r--r-- | routers/web/repo/main_test.go | 4 | ||||
-rw-r--r-- | routers/web/repo/projects_test.go | 4 | ||||
-rw-r--r-- | routers/web/repo/release_test.go | 3 | ||||
-rw-r--r-- | routers/web/repo/settings_test.go | 23 | ||||
-rw-r--r-- | routers/web/repo/wiki_test.go | 20 |
7 files changed, 40 insertions, 37 deletions
diff --git a/routers/web/repo/editor_test.go b/routers/web/repo/editor_test.go index 8ab1fe1ee8..77f94ff550 100644 --- a/routers/web/repo/editor_test.go +++ b/routers/web/repo/editor_test.go @@ -7,7 +7,7 @@ package repo import ( "testing" - "code.gitea.io/gitea/models/db" + "code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/test" @@ -15,7 +15,7 @@ import ( ) func TestCleanUploadName(t *testing.T) { - db.PrepareTestEnv(t) + unittest.PrepareTestEnv(t) var kases = map[string]string{ ".git/refs/master": "", @@ -41,7 +41,7 @@ func TestCleanUploadName(t *testing.T) { } func TestGetUniquePatchBranchName(t *testing.T) { - db.PrepareTestEnv(t) + unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "user2/repo1") ctx.SetParams(":id", "1") test.LoadRepo(t, ctx, 1) @@ -56,7 +56,7 @@ func TestGetUniquePatchBranchName(t *testing.T) { } func TestGetClosestParentWithFiles(t *testing.T) { - db.PrepareTestEnv(t) + unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "user2/repo1") ctx.SetParams(":id", "1") test.LoadRepo(t, ctx, 1) diff --git a/routers/web/repo/issue_label_test.go b/routers/web/repo/issue_label_test.go index 8c3caabe17..98fa9eb968 100644 --- a/routers/web/repo/issue_label_test.go +++ b/routers/web/repo/issue_label_test.go @@ -11,6 +11,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + "code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/modules/test" "code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/services/forms" @@ -30,7 +31,7 @@ func int64SliceToCommaSeparated(a []int64) string { } func TestInitializeLabels(t *testing.T) { - db.PrepareTestEnv(t) + unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "user2/repo1/labels/initialize") test.LoadUser(t, ctx, 2) test.LoadRepo(t, ctx, 2) @@ -46,7 +47,7 @@ func TestInitializeLabels(t *testing.T) { } func TestRetrieveLabels(t *testing.T) { - db.PrepareTestEnv(t) + unittest.PrepareTestEnv(t) for _, testCase := range []struct { RepoID int64 Sort string @@ -73,7 +74,7 @@ func TestRetrieveLabels(t *testing.T) { } func TestNewLabel(t *testing.T) { - db.PrepareTestEnv(t) + unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "user2/repo1/labels/edit") test.LoadUser(t, ctx, 2) test.LoadRepo(t, ctx, 1) @@ -91,7 +92,7 @@ func TestNewLabel(t *testing.T) { } func TestUpdateLabel(t *testing.T) { - db.PrepareTestEnv(t) + unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "user2/repo1/labels/edit") test.LoadUser(t, ctx, 2) test.LoadRepo(t, ctx, 1) @@ -111,7 +112,7 @@ func TestUpdateLabel(t *testing.T) { } func TestDeleteLabel(t *testing.T) { - db.PrepareTestEnv(t) + unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "user2/repo1/labels/delete") test.LoadUser(t, ctx, 2) test.LoadRepo(t, ctx, 1) @@ -124,7 +125,7 @@ func TestDeleteLabel(t *testing.T) { } func TestUpdateIssueLabel_Clear(t *testing.T) { - db.PrepareTestEnv(t) + unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "user2/repo1/issues/labels") test.LoadUser(t, ctx, 2) test.LoadRepo(t, ctx, 1) @@ -149,7 +150,7 @@ func TestUpdateIssueLabel_Toggle(t *testing.T) { {"toggle", []int64{1, 3}, 1, false}, {"toggle", []int64{1, 2}, 2, true}, } { - db.PrepareTestEnv(t) + unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "user2/repo1/issues/labels") test.LoadUser(t, ctx, 2) test.LoadRepo(t, ctx, 1) diff --git a/routers/web/repo/main_test.go b/routers/web/repo/main_test.go index 8322567249..81e3a8e281 100644 --- a/routers/web/repo/main_test.go +++ b/routers/web/repo/main_test.go @@ -8,9 +8,9 @@ import ( "path/filepath" "testing" - "code.gitea.io/gitea/models/db" + "code.gitea.io/gitea/models/unittest" ) func TestMain(m *testing.M) { - db.MainTest(m, filepath.Join("..", "..", "..")) + unittest.MainTest(m, filepath.Join("..", "..", "..")) } diff --git a/routers/web/repo/projects_test.go b/routers/web/repo/projects_test.go index d3b78cc775..62fb045740 100644 --- a/routers/web/repo/projects_test.go +++ b/routers/web/repo/projects_test.go @@ -7,14 +7,14 @@ package repo import ( "testing" - "code.gitea.io/gitea/models/db" + "code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/modules/test" "github.com/stretchr/testify/assert" ) func TestCheckProjectBoardChangePermissions(t *testing.T) { - db.PrepareTestEnv(t) + unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "user2/repo1/projects/1/2") test.LoadUser(t, ctx, 2) test.LoadRepo(t, ctx, 1) diff --git a/routers/web/repo/release_test.go b/routers/web/repo/release_test.go index 7ac49c012f..ff54232da7 100644 --- a/routers/web/repo/release_test.go +++ b/routers/web/repo/release_test.go @@ -9,6 +9,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + "code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/modules/test" "code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/services/forms" @@ -44,7 +45,7 @@ func TestNewReleasePost(t *testing.T) { }, }, } { - db.PrepareTestEnv(t) + unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "user2/repo1/releases/new") test.LoadUser(t, ctx, 2) diff --git a/routers/web/repo/settings_test.go b/routers/web/repo/settings_test.go index a3ed271cce..78426f5b79 100644 --- a/routers/web/repo/settings_test.go +++ b/routers/web/repo/settings_test.go @@ -11,6 +11,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + "code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/test" @@ -43,7 +44,7 @@ func TestAddReadOnlyDeployKey(t *testing.T) { } else { return } - db.PrepareTestEnv(t) + unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "user2/repo1/settings/keys") @@ -72,7 +73,7 @@ func TestAddReadWriteOnlyDeployKey(t *testing.T) { return } - db.PrepareTestEnv(t) + unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "user2/repo1/settings/keys") @@ -97,7 +98,7 @@ func TestAddReadWriteOnlyDeployKey(t *testing.T) { func TestCollaborationPost(t *testing.T) { - db.PrepareTestEnv(t) + unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "user2/repo1/issues/labels") test.LoadUser(t, ctx, 2) test.LoadUser(t, ctx, 4) @@ -133,7 +134,7 @@ func TestCollaborationPost(t *testing.T) { func TestCollaborationPost_InactiveUser(t *testing.T) { - db.PrepareTestEnv(t) + unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "user2/repo1/issues/labels") test.LoadUser(t, ctx, 2) test.LoadUser(t, ctx, 9) @@ -157,7 +158,7 @@ func TestCollaborationPost_InactiveUser(t *testing.T) { func TestCollaborationPost_AddCollaboratorTwice(t *testing.T) { - db.PrepareTestEnv(t) + unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "user2/repo1/issues/labels") test.LoadUser(t, ctx, 2) test.LoadUser(t, ctx, 4) @@ -199,7 +200,7 @@ func TestCollaborationPost_AddCollaboratorTwice(t *testing.T) { func TestCollaborationPost_NonExistentUser(t *testing.T) { - db.PrepareTestEnv(t) + unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "user2/repo1/issues/labels") test.LoadUser(t, ctx, 2) test.LoadRepo(t, ctx, 1) @@ -221,7 +222,7 @@ func TestCollaborationPost_NonExistentUser(t *testing.T) { } func TestAddTeamPost(t *testing.T) { - db.PrepareTestEnv(t) + unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "org26/repo43") ctx.Req.Form.Set("team", "team11") @@ -261,7 +262,7 @@ func TestAddTeamPost(t *testing.T) { } func TestAddTeamPost_NotAllowed(t *testing.T) { - db.PrepareTestEnv(t) + unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "org26/repo43") ctx.Req.Form.Set("team", "team11") @@ -302,7 +303,7 @@ func TestAddTeamPost_NotAllowed(t *testing.T) { } func TestAddTeamPost_AddTeamTwice(t *testing.T) { - db.PrepareTestEnv(t) + unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "org26/repo43") ctx.Req.Form.Set("team", "team11") @@ -343,7 +344,7 @@ func TestAddTeamPost_AddTeamTwice(t *testing.T) { } func TestAddTeamPost_NonExistentTeam(t *testing.T) { - db.PrepareTestEnv(t) + unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "org26/repo43") ctx.Req.Form.Set("team", "team-non-existent") @@ -376,7 +377,7 @@ func TestAddTeamPost_NonExistentTeam(t *testing.T) { } func TestDeleteTeam(t *testing.T) { - db.PrepareTestEnv(t) + unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "org3/team1/repo3") ctx.Req.Form.Set("id", "2") diff --git a/routers/web/repo/wiki_test.go b/routers/web/repo/wiki_test.go index 14cb893d46..cf49f19afe 100644 --- a/routers/web/repo/wiki_test.go +++ b/routers/web/repo/wiki_test.go @@ -10,7 +10,7 @@ import ( "testing" "code.gitea.io/gitea/models" - "code.gitea.io/gitea/models/db" + "code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/test" "code.gitea.io/gitea/modules/web" @@ -74,7 +74,7 @@ func assertPagesMetas(t *testing.T, expectedNames []string, metas interface{}) { } func TestWiki(t *testing.T) { - db.PrepareTestEnv(t) + unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "user2/repo1/wiki/_pages") ctx.SetParams(":page", "Home") @@ -86,7 +86,7 @@ func TestWiki(t *testing.T) { } func TestWikiPages(t *testing.T) { - db.PrepareTestEnv(t) + unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "user2/repo1/wiki/_pages") test.LoadRepo(t, ctx, 1) @@ -96,7 +96,7 @@ func TestWikiPages(t *testing.T) { } func TestNewWiki(t *testing.T) { - db.PrepareTestEnv(t) + unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "user2/repo1/wiki/_new") test.LoadUser(t, ctx, 2) @@ -111,7 +111,7 @@ func TestNewWikiPost(t *testing.T) { "New page", "&&&&", } { - db.PrepareTestEnv(t) + unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "user2/repo1/wiki/_new") test.LoadUser(t, ctx, 2) @@ -129,7 +129,7 @@ func TestNewWikiPost(t *testing.T) { } func TestNewWikiPost_ReservedName(t *testing.T) { - db.PrepareTestEnv(t) + unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "user2/repo1/wiki/_new") test.LoadUser(t, ctx, 2) @@ -146,7 +146,7 @@ func TestNewWikiPost_ReservedName(t *testing.T) { } func TestEditWiki(t *testing.T) { - db.PrepareTestEnv(t) + unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "user2/repo1/wiki/_edit/Home") ctx.SetParams(":page", "Home") @@ -163,7 +163,7 @@ func TestEditWikiPost(t *testing.T) { "Home", "New/<page>", } { - db.PrepareTestEnv(t) + unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "user2/repo1/wiki/_new/Home") ctx.SetParams(":page", "Home") test.LoadUser(t, ctx, 2) @@ -184,7 +184,7 @@ func TestEditWikiPost(t *testing.T) { } func TestDeleteWikiPagePost(t *testing.T) { - db.PrepareTestEnv(t) + unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "user2/repo1/wiki/Home/delete") test.LoadUser(t, ctx, 2) @@ -203,7 +203,7 @@ func TestWikiRaw(t *testing.T) { "Page With Spaced Name.md": "text/plain; charset=utf-8", "Page-With-Spaced-Name.md": "text/plain; charset=utf-8", } { - db.PrepareTestEnv(t) + unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "user2/repo1/wiki/raw/"+filepath) ctx.SetParams("*", filepath) |