1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-23 02:38:35 +00:00

Decouple unit test code from business code (#17623)

This commit is contained in:
wxiaoguang
2021-11-12 22:36:47 +08:00
committed by GitHub
parent 7f802631c5
commit df64fa4865
136 changed files with 1058 additions and 830 deletions

View File

@@ -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/repository"
"code.gitea.io/gitea/modules/setting"
@@ -16,7 +17,7 @@ import (
)
func TestUpdateIssuesCommit(t *testing.T) {
assert.NoError(t, db.PrepareTestDatabase())
assert.NoError(t, unittest.PrepareTestDatabase())
pushCommits := []*repository.PushCommit{
{
Sha1: "abcdef1",
@@ -118,7 +119,7 @@ func TestUpdateIssuesCommit(t *testing.T) {
}
func TestUpdateIssuesCommit_Colon(t *testing.T) {
assert.NoError(t, db.PrepareTestDatabase())
assert.NoError(t, unittest.PrepareTestDatabase())
pushCommits := []*repository.PushCommit{
{
Sha1: "abcdef2",
@@ -143,7 +144,7 @@ func TestUpdateIssuesCommit_Colon(t *testing.T) {
}
func TestUpdateIssuesCommit_Issue5957(t *testing.T) {
assert.NoError(t, db.PrepareTestDatabase())
assert.NoError(t, unittest.PrepareTestDatabase())
user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
// Test that push to a non-default branch closes an issue.
@@ -177,7 +178,7 @@ func TestUpdateIssuesCommit_Issue5957(t *testing.T) {
}
func TestUpdateIssuesCommit_AnotherRepo(t *testing.T) {
assert.NoError(t, db.PrepareTestDatabase())
assert.NoError(t, unittest.PrepareTestDatabase())
user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
// Test that a push to default branch closes issue in another repo
@@ -212,7 +213,7 @@ func TestUpdateIssuesCommit_AnotherRepo(t *testing.T) {
}
func TestUpdateIssuesCommit_AnotherRepo_FullAddress(t *testing.T) {
assert.NoError(t, db.PrepareTestDatabase())
assert.NoError(t, unittest.PrepareTestDatabase())
user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
// Test that a push to default branch closes issue in another repo
@@ -247,7 +248,7 @@ func TestUpdateIssuesCommit_AnotherRepo_FullAddress(t *testing.T) {
}
func TestUpdateIssuesCommit_AnotherRepoNoPermission(t *testing.T) {
assert.NoError(t, db.PrepareTestDatabase())
assert.NoError(t, unittest.PrepareTestDatabase())
user := db.AssertExistsAndLoadBean(t, &models.User{ID: 10}).(*models.User)
// Test that a push with close reference *can not* close issue

View File

@@ -7,7 +7,8 @@ package repofiles
import (
"testing"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unittest"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/test"
@@ -15,7 +16,7 @@ import (
)
func TestGetBlobBySHA(t *testing.T) {
db.PrepareTestEnv(t)
unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1")
test.LoadRepo(t, ctx, 1)
test.LoadRepoCommit(t, ctx)

View File

@@ -8,7 +8,8 @@ import (
"path/filepath"
"testing"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unittest"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/test"
@@ -16,7 +17,7 @@ import (
)
func TestMain(m *testing.M) {
db.MainTest(m, filepath.Join("..", ".."))
unittest.MainTest(m, filepath.Join("..", ".."))
}
func getExpectedReadmeContentsResponse() *api.ContentsResponse {
@@ -49,7 +50,7 @@ func getExpectedReadmeContentsResponse() *api.ContentsResponse {
}
func TestGetContents(t *testing.T) {
db.PrepareTestEnv(t)
unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1")
ctx.SetParams(":id", "1")
test.LoadRepo(t, ctx, 1)
@@ -77,7 +78,7 @@ func TestGetContents(t *testing.T) {
}
func TestGetContentsOrListForDir(t *testing.T) {
db.PrepareTestEnv(t)
unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1")
ctx.SetParams(":id", "1")
test.LoadRepo(t, ctx, 1)
@@ -112,7 +113,7 @@ func TestGetContentsOrListForDir(t *testing.T) {
}
func TestGetContentsOrListForFile(t *testing.T) {
db.PrepareTestEnv(t)
unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1")
ctx.SetParams(":id", "1")
test.LoadRepo(t, ctx, 1)
@@ -140,7 +141,7 @@ func TestGetContentsOrListForFile(t *testing.T) {
}
func TestGetContentsErrors(t *testing.T) {
db.PrepareTestEnv(t)
unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1")
ctx.SetParams(":id", "1")
test.LoadRepo(t, ctx, 1)
@@ -171,7 +172,7 @@ func TestGetContentsErrors(t *testing.T) {
}
func TestGetContentsOrListErrors(t *testing.T) {
db.PrepareTestEnv(t)
unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1")
ctx.SetParams(":id", "1")
test.LoadRepo(t, ctx, 1)
@@ -202,7 +203,7 @@ func TestGetContentsOrListErrors(t *testing.T) {
}
func TestGetContentsOrListOfEmptyRepos(t *testing.T) {
db.PrepareTestEnv(t)
unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo15")
ctx.SetParams(":id", "15")
test.LoadRepo(t, ctx, 15)

View File

@@ -8,7 +8,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/test"
"code.gitea.io/gitea/services/gitdiff"
@@ -16,7 +16,7 @@ import (
)
func TestGetDiffPreview(t *testing.T) {
db.PrepareTestEnv(t)
unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1")
ctx.SetParams(":id", "1")
test.LoadRepo(t, ctx, 1)
@@ -129,7 +129,7 @@ func TestGetDiffPreview(t *testing.T) {
}
func TestGetDiffPreviewErrors(t *testing.T) {
db.PrepareTestEnv(t)
unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1")
ctx.SetParams(":id", "1")
test.LoadRepo(t, ctx, 1)

View File

@@ -7,7 +7,7 @@ package repofiles
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/setting"
api "code.gitea.io/gitea/modules/structs"
@@ -81,7 +81,7 @@ func getExpectedFileResponse() *api.FileResponse {
}
func TestGetFileResponseFromCommit(t *testing.T) {
db.PrepareTestEnv(t)
unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1")
ctx.SetParams(":id", "1")
test.LoadRepo(t, ctx, 1)

View File

@@ -7,7 +7,8 @@ package repofiles
import (
"testing"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unittest"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/test"
@@ -15,7 +16,7 @@ import (
)
func TestGetTreeBySHA(t *testing.T) {
db.PrepareTestEnv(t)
unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1")
test.LoadRepo(t, ctx, 1)
test.LoadRepoCommit(t, ctx)