mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Decouple unit test, remove intermediate unittestbridge
package (#17662)
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
@@ -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{
|
||||
|
@@ -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,
|
||||
|
@@ -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
|
||||
|
@@ -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)
|
||||
|
@@ -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)
|
||||
|
||||
|
@@ -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())
|
||||
|
@@ -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{})
|
||||
}
|
||||
|
@@ -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{})
|
||||
}
|
||||
|
@@ -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)
|
||||
|
@@ -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)
|
||||
|
@@ -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,
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
}
|
Reference in New Issue
Block a user