aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2021-11-16 16:53:21 +0800
committerGitHub <noreply@github.com>2021-11-16 16:53:21 +0800
commit81926d61db3dac223a75ea49eab893b25a089587 (patch)
tree627d2f19a008089f3a688e9a94a2cc8d2017afe2 /modules
parent23bd7b1211a80aa3b0dcb60ec4a1c0089ff28dd4 (diff)
downloadgitea-81926d61db3dac223a75ea49eab893b25a089587.tar.gz
gitea-81926d61db3dac223a75ea49eab893b25a089587.zip
Decouple unit test, remove intermediate `unittestbridge` package (#17662)
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'modules')
-rw-r--r--modules/convert/git_commit_test.go3
-rw-r--r--modules/convert/issue_test.go5
-rw-r--r--modules/convert/pull_test.go7
-rw-r--r--modules/convert/user_test.go7
-rw-r--r--modules/migrations/gitea_uploader_test.go4
-rw-r--r--modules/migrations/migrate_test.go5
-rw-r--r--modules/notification/action/action_test.go11
-rw-r--r--modules/repofiles/action_test.go109
-rw-r--r--modules/repository/commits_test.go3
-rw-r--r--modules/repository/create_test.go3
-rw-r--r--modules/repository/fork_test.go5
-rw-r--r--modules/test/context_tests.go6
-rw-r--r--modules/unittestbridge/unittestbridge.go46
13 files changed, 79 insertions, 135 deletions
diff --git a/modules/convert/git_commit_test.go b/modules/convert/git_commit_test.go
index 3cb55c6a6f..aacdb1ad7c 100644
--- a/modules/convert/git_commit_test.go
+++ b/modules/convert/git_commit_test.go
@@ -9,7 +9,6 @@ import (
"time"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/git"
api "code.gitea.io/gitea/modules/structs"
@@ -20,7 +19,7 @@ import (
func TestToCommitMeta(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
- headRepo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ headRepo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
sha1, _ := git.NewIDFromString("0000000000000000000000000000000000000000")
signature := &git.Signature{Name: "Test Signature", Email: "test@email.com", When: time.Unix(0, 0)}
tag := &git.Tag{
diff --git a/modules/convert/issue_test.go b/modules/convert/issue_test.go
index e44733c46d..21ca7469e1 100644
--- a/modules/convert/issue_test.go
+++ b/modules/convert/issue_test.go
@@ -10,7 +10,6 @@ import (
"time"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
@@ -21,8 +20,8 @@ import (
func TestLabel_ToLabel(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
- label := db.AssertExistsAndLoadBean(t, &models.Label{ID: 1}).(*models.Label)
- repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: label.RepoID}).(*models.Repository)
+ label := unittest.AssertExistsAndLoadBean(t, &models.Label{ID: 1}).(*models.Label)
+ repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: label.RepoID}).(*models.Repository)
assert.Equal(t, &api.Label{
ID: label.ID,
Name: label.Name,
diff --git a/modules/convert/pull_test.go b/modules/convert/pull_test.go
index f5310eb825..844011b8cc 100644
--- a/modules/convert/pull_test.go
+++ b/modules/convert/pull_test.go
@@ -8,7 +8,6 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/structs"
@@ -18,8 +17,8 @@ import (
func TestPullRequest_APIFormat(t *testing.T) {
//with HeadRepo
assert.NoError(t, unittest.PrepareTestDatabase())
- headRepo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
- pr := db.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 1}).(*models.PullRequest)
+ headRepo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ pr := unittest.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 1}).(*models.PullRequest)
assert.NoError(t, pr.LoadAttributes())
assert.NoError(t, pr.LoadIssue())
apiPullRequest := ToAPIPullRequest(pr, nil)
@@ -33,7 +32,7 @@ func TestPullRequest_APIFormat(t *testing.T) {
}, apiPullRequest.Head)
//withOut HeadRepo
- pr = db.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 1}).(*models.PullRequest)
+ pr = unittest.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 1}).(*models.PullRequest)
assert.NoError(t, pr.LoadIssue())
assert.NoError(t, pr.LoadAttributes())
// simulate fork deletion
diff --git a/modules/convert/user_test.go b/modules/convert/user_test.go
index fe26456f5d..ce174e3076 100644
--- a/modules/convert/user_test.go
+++ b/modules/convert/user_test.go
@@ -8,7 +8,6 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unittest"
api "code.gitea.io/gitea/modules/structs"
@@ -18,13 +17,13 @@ import (
func TestUser_ToUser(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
- user1 := db.AssertExistsAndLoadBean(t, &models.User{ID: 1, IsAdmin: true}).(*models.User)
+ user1 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 1, IsAdmin: true}).(*models.User)
apiUser := toUser(user1, true, true)
assert.True(t, apiUser.IsAdmin)
assert.Contains(t, apiUser.AvatarURL, "://")
- user2 := db.AssertExistsAndLoadBean(t, &models.User{ID: 2, IsAdmin: false}).(*models.User)
+ user2 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2, IsAdmin: false}).(*models.User)
apiUser = toUser(user2, true, true)
assert.False(t, apiUser.IsAdmin)
@@ -33,7 +32,7 @@ func TestUser_ToUser(t *testing.T) {
assert.False(t, apiUser.IsAdmin)
assert.EqualValues(t, api.VisibleTypePublic.String(), apiUser.Visibility)
- user31 := db.AssertExistsAndLoadBean(t, &models.User{ID: 31, IsAdmin: false, Visibility: api.VisibleTypePrivate}).(*models.User)
+ user31 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 31, IsAdmin: false, Visibility: api.VisibleTypePrivate}).(*models.User)
apiUser = toUser(user31, true, true)
assert.False(t, apiUser.IsAdmin)
diff --git a/modules/migrations/gitea_uploader_test.go b/modules/migrations/gitea_uploader_test.go
index b5763f30d9..99de3884ce 100644
--- a/modules/migrations/gitea_uploader_test.go
+++ b/modules/migrations/gitea_uploader_test.go
@@ -27,7 +27,7 @@ func TestGiteaUploadRepo(t *testing.T) {
unittest.PrepareTestEnv(t)
- user := db.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
+ user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
var (
downloader = NewGithubDownloaderV3(context.Background(), "https://github.com", "", "", "", "go-xorm", "builder")
@@ -52,7 +52,7 @@ func TestGiteaUploadRepo(t *testing.T) {
}, nil)
assert.NoError(t, err)
- repo := db.AssertExistsAndLoadBean(t, &models.Repository{OwnerID: user.ID, Name: repoName}).(*models.Repository)
+ repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{OwnerID: user.ID, Name: repoName}).(*models.Repository)
assert.True(t, repo.HasWiki())
assert.EqualValues(t, models.RepositoryReady, repo.Status)
diff --git a/modules/migrations/migrate_test.go b/modules/migrations/migrate_test.go
index aecc263cc6..325064697e 100644
--- a/modules/migrations/migrate_test.go
+++ b/modules/migrations/migrate_test.go
@@ -9,7 +9,6 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/setting"
@@ -19,8 +18,8 @@ import (
func TestMigrateWhiteBlocklist(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
- adminUser := db.AssertExistsAndLoadBean(t, &models.User{Name: "user1"}).(*models.User)
- nonAdminUser := db.AssertExistsAndLoadBean(t, &models.User{Name: "user2"}).(*models.User)
+ adminUser := unittest.AssertExistsAndLoadBean(t, &models.User{Name: "user1"}).(*models.User)
+ nonAdminUser := unittest.AssertExistsAndLoadBean(t, &models.User{Name: "user2"}).(*models.User)
setting.Migrations.AllowedDomains = []string{"github.com"}
assert.NoError(t, Init())
diff --git a/modules/notification/action/action_test.go b/modules/notification/action/action_test.go
index e57069ed9a..3adcae83fd 100644
--- a/modules/notification/action/action_test.go
+++ b/modules/notification/action/action_test.go
@@ -10,7 +10,6 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unittest"
"github.com/stretchr/testify/assert"
)
@@ -22,8 +21,8 @@ func TestMain(m *testing.M) {
func TestRenameRepoAction(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
- user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
- repo := db.AssertExistsAndLoadBean(t, &models.Repository{OwnerID: user.ID}).(*models.Repository)
+ user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{OwnerID: user.ID}).(*models.Repository)
repo.Owner = user
oldRepoName := repo.Name
@@ -40,10 +39,10 @@ func TestRenameRepoAction(t *testing.T) {
IsPrivate: repo.IsPrivate,
Content: oldRepoName,
}
- db.AssertNotExistsBean(t, actionBean)
+ unittest.AssertNotExistsBean(t, actionBean)
NewNotifier().NotifyRenameRepository(user, repo, oldRepoName)
- db.AssertExistsAndLoadBean(t, actionBean)
- models.CheckConsistencyFor(t, &models.Action{})
+ unittest.AssertExistsAndLoadBean(t, actionBean)
+ unittest.CheckConsistencyFor(t, &models.Action{})
}
diff --git a/modules/repofiles/action_test.go b/modules/repofiles/action_test.go
index 59cb4df160..d320413dbb 100644
--- a/modules/repofiles/action_test.go
+++ b/modules/repofiles/action_test.go
@@ -8,7 +8,6 @@ import (
"testing"
"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"
@@ -45,8 +44,8 @@ func TestUpdateIssuesCommit(t *testing.T) {
},
}
- user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
- repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
repo.Owner = user
commentBean := &models.Comment{
@@ -57,12 +56,12 @@ func TestUpdateIssuesCommit(t *testing.T) {
}
issueBean := &models.Issue{RepoID: repo.ID, Index: 4}
- db.AssertNotExistsBean(t, commentBean)
- db.AssertNotExistsBean(t, &models.Issue{RepoID: repo.ID, Index: 2}, "is_closed=1")
+ unittest.AssertNotExistsBean(t, commentBean)
+ unittest.AssertNotExistsBean(t, &models.Issue{RepoID: repo.ID, Index: 2}, "is_closed=1")
assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, repo.DefaultBranch))
- db.AssertExistsAndLoadBean(t, commentBean)
- db.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
- models.CheckConsistencyFor(t, &models.Action{})
+ unittest.AssertExistsAndLoadBean(t, commentBean)
+ unittest.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
+ unittest.CheckConsistencyFor(t, &models.Action{})
// Test that push to a non-default branch closes no issue.
pushCommits = []*repository.PushCommit{
@@ -75,7 +74,7 @@ func TestUpdateIssuesCommit(t *testing.T) {
Message: "close #1",
},
}
- repo = db.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
+ repo = unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
commentBean = &models.Comment{
Type: models.CommentTypeCommitRef,
CommitSHA: "abcdef1",
@@ -84,12 +83,12 @@ func TestUpdateIssuesCommit(t *testing.T) {
}
issueBean = &models.Issue{RepoID: repo.ID, Index: 1}
- db.AssertNotExistsBean(t, commentBean)
- db.AssertNotExistsBean(t, &models.Issue{RepoID: repo.ID, Index: 1}, "is_closed=1")
+ unittest.AssertNotExistsBean(t, commentBean)
+ unittest.AssertNotExistsBean(t, &models.Issue{RepoID: repo.ID, Index: 1}, "is_closed=1")
assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, "non-existing-branch"))
- db.AssertExistsAndLoadBean(t, commentBean)
- db.AssertNotExistsBean(t, issueBean, "is_closed=1")
- models.CheckConsistencyFor(t, &models.Action{})
+ unittest.AssertExistsAndLoadBean(t, commentBean)
+ unittest.AssertNotExistsBean(t, issueBean, "is_closed=1")
+ unittest.CheckConsistencyFor(t, &models.Action{})
pushCommits = []*repository.PushCommit{
{
@@ -101,7 +100,7 @@ func TestUpdateIssuesCommit(t *testing.T) {
Message: "close " + setting.AppURL + repo.FullName() + "/pulls/1",
},
}
- repo = db.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
+ repo = unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
commentBean = &models.Comment{
Type: models.CommentTypeCommitRef,
CommitSHA: "abcdef3",
@@ -110,12 +109,12 @@ func TestUpdateIssuesCommit(t *testing.T) {
}
issueBean = &models.Issue{RepoID: repo.ID, Index: 1}
- db.AssertNotExistsBean(t, commentBean)
- db.AssertNotExistsBean(t, &models.Issue{RepoID: repo.ID, Index: 1}, "is_closed=1")
+ unittest.AssertNotExistsBean(t, commentBean)
+ unittest.AssertNotExistsBean(t, &models.Issue{RepoID: repo.ID, Index: 1}, "is_closed=1")
assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, repo.DefaultBranch))
- db.AssertExistsAndLoadBean(t, commentBean)
- db.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
- models.CheckConsistencyFor(t, &models.Action{})
+ unittest.AssertExistsAndLoadBean(t, commentBean)
+ unittest.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
+ unittest.CheckConsistencyFor(t, &models.Action{})
}
func TestUpdateIssuesCommit_Colon(t *testing.T) {
@@ -131,21 +130,21 @@ func TestUpdateIssuesCommit_Colon(t *testing.T) {
},
}
- user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
- repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
repo.Owner = user
issueBean := &models.Issue{RepoID: repo.ID, Index: 4}
- db.AssertNotExistsBean(t, &models.Issue{RepoID: repo.ID, Index: 2}, "is_closed=1")
+ unittest.AssertNotExistsBean(t, &models.Issue{RepoID: repo.ID, Index: 2}, "is_closed=1")
assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, repo.DefaultBranch))
- db.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
- models.CheckConsistencyFor(t, &models.Action{})
+ unittest.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
+ unittest.CheckConsistencyFor(t, &models.Action{})
}
func TestUpdateIssuesCommit_Issue5957(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
- user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
// Test that push to a non-default branch closes an issue.
pushCommits := []*repository.PushCommit{
@@ -159,7 +158,7 @@ func TestUpdateIssuesCommit_Issue5957(t *testing.T) {
},
}
- repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
+ repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
commentBean := &models.Comment{
Type: models.CommentTypeCommitRef,
CommitSHA: "abcdef1",
@@ -169,17 +168,17 @@ func TestUpdateIssuesCommit_Issue5957(t *testing.T) {
issueBean := &models.Issue{RepoID: repo.ID, Index: 2, ID: 7}
- db.AssertNotExistsBean(t, commentBean)
- db.AssertNotExistsBean(t, issueBean, "is_closed=1")
+ unittest.AssertNotExistsBean(t, commentBean)
+ unittest.AssertNotExistsBean(t, issueBean, "is_closed=1")
assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, "non-existing-branch"))
- db.AssertExistsAndLoadBean(t, commentBean)
- db.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
- models.CheckConsistencyFor(t, &models.Action{})
+ unittest.AssertExistsAndLoadBean(t, commentBean)
+ unittest.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
+ unittest.CheckConsistencyFor(t, &models.Action{})
}
func TestUpdateIssuesCommit_AnotherRepo(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
- user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
// Test that a push to default branch closes issue in another repo
// If the user also has push permissions to that repo
@@ -194,7 +193,7 @@ func TestUpdateIssuesCommit_AnotherRepo(t *testing.T) {
},
}
- repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
+ repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
commentBean := &models.Comment{
Type: models.CommentTypeCommitRef,
CommitSHA: "abcdef1",
@@ -204,17 +203,17 @@ func TestUpdateIssuesCommit_AnotherRepo(t *testing.T) {
issueBean := &models.Issue{RepoID: 1, Index: 1, ID: 1}
- db.AssertNotExistsBean(t, commentBean)
- db.AssertNotExistsBean(t, issueBean, "is_closed=1")
+ unittest.AssertNotExistsBean(t, commentBean)
+ unittest.AssertNotExistsBean(t, issueBean, "is_closed=1")
assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, repo.DefaultBranch))
- db.AssertExistsAndLoadBean(t, commentBean)
- db.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
- models.CheckConsistencyFor(t, &models.Action{})
+ unittest.AssertExistsAndLoadBean(t, commentBean)
+ unittest.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
+ unittest.CheckConsistencyFor(t, &models.Action{})
}
func TestUpdateIssuesCommit_AnotherRepo_FullAddress(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
- user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
// Test that a push to default branch closes issue in another repo
// If the user also has push permissions to that repo
@@ -229,7 +228,7 @@ func TestUpdateIssuesCommit_AnotherRepo_FullAddress(t *testing.T) {
},
}
- repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
+ repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
commentBean := &models.Comment{
Type: models.CommentTypeCommitRef,
CommitSHA: "abcdef1",
@@ -239,17 +238,17 @@ func TestUpdateIssuesCommit_AnotherRepo_FullAddress(t *testing.T) {
issueBean := &models.Issue{RepoID: 1, Index: 1, ID: 1}
- db.AssertNotExistsBean(t, commentBean)
- db.AssertNotExistsBean(t, issueBean, "is_closed=1")
+ unittest.AssertNotExistsBean(t, commentBean)
+ unittest.AssertNotExistsBean(t, issueBean, "is_closed=1")
assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, repo.DefaultBranch))
- db.AssertExistsAndLoadBean(t, commentBean)
- db.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
- models.CheckConsistencyFor(t, &models.Action{})
+ unittest.AssertExistsAndLoadBean(t, commentBean)
+ unittest.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
+ unittest.CheckConsistencyFor(t, &models.Action{})
}
func TestUpdateIssuesCommit_AnotherRepoNoPermission(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
- user := db.AssertExistsAndLoadBean(t, &models.User{ID: 10}).(*models.User)
+ user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 10}).(*models.User)
// Test that a push with close reference *can not* close issue
// If the committer doesn't have push rights in that repo
@@ -272,7 +271,7 @@ func TestUpdateIssuesCommit_AnotherRepoNoPermission(t *testing.T) {
},
}
- repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 6}).(*models.Repository)
+ repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 6}).(*models.Repository)
commentBean := &models.Comment{
Type: models.CommentTypeCommitRef,
CommitSHA: "abcdef3",
@@ -288,12 +287,12 @@ func TestUpdateIssuesCommit_AnotherRepoNoPermission(t *testing.T) {
issueBean := &models.Issue{RepoID: 3, Index: 1, ID: 6}
- db.AssertNotExistsBean(t, commentBean)
- db.AssertNotExistsBean(t, commentBean2)
- db.AssertNotExistsBean(t, issueBean, "is_closed=1")
+ unittest.AssertNotExistsBean(t, commentBean)
+ unittest.AssertNotExistsBean(t, commentBean2)
+ unittest.AssertNotExistsBean(t, issueBean, "is_closed=1")
assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, repo.DefaultBranch))
- db.AssertNotExistsBean(t, commentBean)
- db.AssertNotExistsBean(t, commentBean2)
- db.AssertNotExistsBean(t, issueBean, "is_closed=1")
- models.CheckConsistencyFor(t, &models.Action{})
+ unittest.AssertNotExistsBean(t, commentBean)
+ unittest.AssertNotExistsBean(t, commentBean2)
+ unittest.AssertNotExistsBean(t, issueBean, "is_closed=1")
+ unittest.CheckConsistencyFor(t, &models.Action{})
}
diff --git a/modules/repository/commits_test.go b/modules/repository/commits_test.go
index c47d9cf48c..0d6c2e4c5c 100644
--- a/modules/repository/commits_test.go
+++ b/modules/repository/commits_test.go
@@ -11,7 +11,6 @@ import (
"time"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/git"
"github.com/stretchr/testify/assert"
@@ -49,7 +48,7 @@ func TestPushCommits_ToAPIPayloadCommits(t *testing.T) {
}
pushCommits.HeadCommit = &PushCommit{Sha1: "69554a6"}
- repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository)
+ repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository)
payloadCommits, headCommit, err := pushCommits.ToAPIPayloadCommits(repo.RepoPath(), "/user2/repo16")
assert.NoError(t, err)
assert.Len(t, payloadCommits, 3)
diff --git a/modules/repository/create_test.go b/modules/repository/create_test.go
index d833017160..2e27ab0d7d 100644
--- a/modules/repository/create_test.go
+++ b/modules/repository/create_test.go
@@ -9,7 +9,6 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/structs"
@@ -20,7 +19,7 @@ func TestIncludesAllRepositoriesTeams(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
testTeamRepositories := func(teamID int64, repoIds []int64) {
- team := db.AssertExistsAndLoadBean(t, &models.Team{ID: teamID}).(*models.Team)
+ team := unittest.AssertExistsAndLoadBean(t, &models.Team{ID: teamID}).(*models.Team)
assert.NoError(t, team.GetRepositories(&models.SearchTeamOptions{}), "%s: GetRepositories", team.Name)
assert.Len(t, team.Repos, team.NumRepos, "%s: len repo", team.Name)
assert.Len(t, team.Repos, len(repoIds), "%s: repo count", team.Name)
diff --git a/modules/repository/fork_test.go b/modules/repository/fork_test.go
index bfb813adbc..197d76b056 100644
--- a/modules/repository/fork_test.go
+++ b/modules/repository/fork_test.go
@@ -8,7 +8,6 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unittest"
"github.com/stretchr/testify/assert"
)
@@ -17,8 +16,8 @@ func TestForkRepository(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
// user 13 has already forked repo10
- user := db.AssertExistsAndLoadBean(t, &models.User{ID: 13}).(*models.User)
- repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 10}).(*models.Repository)
+ user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 13}).(*models.User)
+ repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 10}).(*models.Repository)
fork, err := ForkRepository(user, user, models.ForkRepoOptions{
BaseRepo: repo,
diff --git a/modules/test/context_tests.go b/modules/test/context_tests.go
index 02723d8c38..eb1a54d86f 100644
--- a/modules/test/context_tests.go
+++ b/modules/test/context_tests.go
@@ -14,7 +14,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/context"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/web/middleware"
@@ -53,7 +53,7 @@ func MockContext(t *testing.T, path string) *context.Context {
// LoadRepo load a repo into a test context.
func LoadRepo(t *testing.T, ctx *context.Context, repoID int64) {
ctx.Repo = &context.Repository{}
- ctx.Repo.Repository = db.AssertExistsAndLoadBean(t, &models.Repository{ID: repoID}).(*models.Repository)
+ ctx.Repo.Repository = unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: repoID}).(*models.Repository)
var err error
ctx.Repo.Owner, err = models.GetUserByID(ctx.Repo.Repository.OwnerID)
assert.NoError(t, err)
@@ -78,7 +78,7 @@ func LoadRepoCommit(t *testing.T, ctx *context.Context) {
// LoadUser load a user into a test context.
func LoadUser(t *testing.T, ctx *context.Context, userID int64) {
- ctx.User = db.AssertExistsAndLoadBean(t, &models.User{ID: userID}).(*models.User)
+ ctx.User = unittest.AssertExistsAndLoadBean(t, &models.User{ID: userID}).(*models.User)
}
// LoadGitRepo load a git repo into a test context. Requires that ctx.Repo has
diff --git a/modules/unittestbridge/unittestbridge.go b/modules/unittestbridge/unittestbridge.go
deleted file mode 100644
index 273cf5e70f..0000000000
--- a/modules/unittestbridge/unittestbridge.go
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright 2021 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
-
-package unittestbridge
-
-// Usage: generally, non-unit-test code shouldn't depend on unit test code.
-// However, we have some code like models.CheckConsistencyFor, which need to do some unit test works.
-// Now we can not decouple models.CheckConsistencyFor from unit test code easily (cycle-import reasons).
-// So we introduce this `unit test bridge`:
-// * When a release binary is built, no testing/assert framework would be compiled into the binary, and CheckConsistencyFor won't run unit test related code
-// * When a unit test binary is built, the unit test code will init this bridge, then CheckConsistencyFor can run unit test related code
-//
-// Tester/Assert are intermediate interfaces, they should NOT be used in new code.
-// One day, if CheckConsistencyFor is clean enough, we can remove these intermediate interfaces.
-
-// Tester is the same as TestingT in "stretchr/testify/assert"
-// Tester can be used in non-unit-test code (ex: models.CheckConsistencyFor), it is used to isolate dependencies
-type Tester interface {
- Errorf(format string, args ...interface{})
-}
-
-// Asserter can be used in non-unit-test code (ex: models.CheckConsistencyFor), it is used to isolate dependencies
-type Asserter interface {
- Tester
- NoError(err error, msgAndArgs ...interface{}) bool
- EqualValues(expected, actual interface{}, msgAndArgs ...interface{}) bool
- Equal(expected, actual interface{}, msgAndArgs ...interface{}) bool
- True(value bool, msgAndArgs ...interface{}) bool
- False(value bool, msgAndArgs ...interface{}) bool
-}
-
-var newAsserterFunc func(t Tester) Asserter
-
-// NewAsserter returns a new asserter, only works in unit test
-func NewAsserter(t Tester) Asserter {
- if newAsserterFunc == nil {
- panic("the newAsserterFunc is not set. you can only use assert in unit test.")
- }
- return newAsserterFunc(t)
-}
-
-// SetNewAsserterFunc in unit test, the asserter must be set first
-func SetNewAsserterFunc(f func(t Tester) Asserter) {
- newAsserterFunc = f
-}