mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-26 06:16:56 +09:00
test: consolidate Go tests (#39962)
Consolidate all Go tests. Coverage is identical to before. Go tests are around 5% faster while being 7% smaller. No non-test code is touched.
This commit is contained in:
1 parent
ce7364e215
commit
8abda62312
388 files changed
+18410
-29561
No files matched your search
@@ -34,6 +34,7 @@ func TestMain(m *testing.M) {
|
||||
// resolves projects owned by the scope its route assigned, so an ID belonging to anyone
|
||||
// else reads as not found rather than leaking across owners.
|
||||
func TestFindColumn(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
projectID string
|
||||
@@ -48,7 +49,6 @@ func TestFindColumn(t *testing.T) {
|
||||
{"owner board cannot reach another owner's project", "4", "4", 1, false, false},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
ctx, _ := contexttest.MockContext(t, "user2/-/projects")
|
||||
contexttest.LoadUser(t, ctx, tc.doerID)
|
||||
if tc.repoScoped {
|
||||
@@ -73,31 +73,28 @@ func TestFindColumn(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMoveIssuesNeedsIssueRead(t *testing.T) {
|
||||
stripTeamIssues := func(t *testing.T) {
|
||||
_, err := db.Exec(t.Context(), "UPDATE team SET authorize = ? WHERE id = ?", perm.AccessModeNone, 2)
|
||||
require.NoError(t, err)
|
||||
_, err = db.DeleteByBean(t.Context(), &organization.TeamUnit{TeamID: 2, Type: unit.TypeIssues})
|
||||
require.NoError(t, err)
|
||||
}
|
||||
archiveRepo3 := func(t *testing.T) {
|
||||
require.NoError(t, repo_model.UpdateRepositoryColsNoAutoTime(t.Context(), &repo_model.Repository{ID: 3, IsArchived: true}, "is_archived"))
|
||||
}
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
doerID int64
|
||||
repoBoard bool
|
||||
prepare func(*testing.T)
|
||||
archived bool
|
||||
status int
|
||||
}{
|
||||
{"OwnerBoardReader", 2, false, nil, http.StatusOK},
|
||||
{"OwnerBoardWithoutIssueAccess", 15, false, nil, http.StatusNotFound},
|
||||
{"OwnerBoardArchivedRepo", 2, false, archiveRepo3, http.StatusLocked},
|
||||
{"RepoBoardProjectsWriterWithoutIssueRead", 4, true, stripTeamIssues, http.StatusNotFound},
|
||||
{"OwnerBoardReader", 2, false, false, http.StatusOK},
|
||||
{"OwnerBoardWithoutIssueAccess", 15, false, false, http.StatusNotFound},
|
||||
{"OwnerBoardArchivedRepo", 2, false, true, http.StatusLocked},
|
||||
{"RepoBoardProjectsWriterWithoutIssueRead", 4, true, false, http.StatusNotFound},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
if tc.prepare != nil {
|
||||
tc.prepare(t)
|
||||
if tc.repoBoard {
|
||||
_, err := db.Exec(t.Context(), "UPDATE team SET authorize = ? WHERE id = ?", perm.AccessModeNone, 2)
|
||||
require.NoError(t, err)
|
||||
_, err = db.DeleteByBean(t.Context(), &organization.TeamUnit{TeamID: 2, Type: unit.TypeIssues})
|
||||
require.NoError(t, err)
|
||||
}
|
||||
if tc.archived {
|
||||
require.NoError(t, repo_model.UpdateRepositoryColsNoAutoTime(t.Context(), &repo_model.Repository{ID: 3, IsArchived: true}, "is_archived"))
|
||||
}
|
||||
ctx, _ := contexttest.MockContext(t, "POST /org3/-/projects")
|
||||
contexttest.LoadUser(t, ctx, tc.doerID)
|
||||
|
||||
Reference in new issue
Block a user