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:
@@ -28,21 +28,21 @@ func addReaction(t *testing.T, doer *User, issue *Issue, comment *Comment, conte
|
||||
func TestIssueAddReaction(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
user1 := db.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
|
||||
user1 := unittest.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
|
||||
|
||||
issue1 := db.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
|
||||
issue1 := unittest.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
|
||||
|
||||
addReaction(t, user1, issue1, nil, "heart")
|
||||
|
||||
db.AssertExistsAndLoadBean(t, &Reaction{Type: "heart", UserID: user1.ID, IssueID: issue1.ID})
|
||||
unittest.AssertExistsAndLoadBean(t, &Reaction{Type: "heart", UserID: user1.ID, IssueID: issue1.ID})
|
||||
}
|
||||
|
||||
func TestIssueAddDuplicateReaction(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
user1 := db.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
|
||||
user1 := unittest.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
|
||||
|
||||
issue1 := db.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
|
||||
issue1 := unittest.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
|
||||
|
||||
addReaction(t, user1, issue1, nil, "heart")
|
||||
|
||||
@@ -54,23 +54,23 @@ func TestIssueAddDuplicateReaction(t *testing.T) {
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, ErrReactionAlreadyExist{Reaction: "heart"}, err)
|
||||
|
||||
existingR := db.AssertExistsAndLoadBean(t, &Reaction{Type: "heart", UserID: user1.ID, IssueID: issue1.ID}).(*Reaction)
|
||||
existingR := unittest.AssertExistsAndLoadBean(t, &Reaction{Type: "heart", UserID: user1.ID, IssueID: issue1.ID}).(*Reaction)
|
||||
assert.Equal(t, existingR.ID, reaction.ID)
|
||||
}
|
||||
|
||||
func TestIssueDeleteReaction(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
user1 := db.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
|
||||
user1 := unittest.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
|
||||
|
||||
issue1 := db.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
|
||||
issue1 := unittest.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
|
||||
|
||||
addReaction(t, user1, issue1, nil, "heart")
|
||||
|
||||
err := DeleteIssueReaction(user1, issue1, "heart")
|
||||
assert.NoError(t, err)
|
||||
|
||||
db.AssertNotExistsBean(t, &Reaction{Type: "heart", UserID: user1.ID, IssueID: issue1.ID})
|
||||
unittest.AssertNotExistsBean(t, &Reaction{Type: "heart", UserID: user1.ID, IssueID: issue1.ID})
|
||||
}
|
||||
|
||||
func TestIssueReactionCount(t *testing.T) {
|
||||
@@ -78,13 +78,13 @@ func TestIssueReactionCount(t *testing.T) {
|
||||
|
||||
setting.UI.ReactionMaxUserNum = 2
|
||||
|
||||
user1 := db.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
|
||||
user2 := db.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
|
||||
user3 := db.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
|
||||
user4 := db.AssertExistsAndLoadBean(t, &User{ID: 4}).(*User)
|
||||
user1 := unittest.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
|
||||
user2 := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
|
||||
user3 := unittest.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
|
||||
user4 := unittest.AssertExistsAndLoadBean(t, &User{ID: 4}).(*User)
|
||||
ghost := NewGhostUser()
|
||||
|
||||
issue := db.AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue)
|
||||
issue := unittest.AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue)
|
||||
|
||||
addReaction(t, user1, issue, nil, "heart")
|
||||
addReaction(t, user2, issue, nil, "heart")
|
||||
@@ -114,29 +114,29 @@ func TestIssueReactionCount(t *testing.T) {
|
||||
func TestIssueCommentAddReaction(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
user1 := db.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
|
||||
user1 := unittest.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
|
||||
|
||||
issue1 := db.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
|
||||
issue1 := unittest.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
|
||||
|
||||
comment1 := db.AssertExistsAndLoadBean(t, &Comment{ID: 1}).(*Comment)
|
||||
comment1 := unittest.AssertExistsAndLoadBean(t, &Comment{ID: 1}).(*Comment)
|
||||
|
||||
addReaction(t, user1, issue1, comment1, "heart")
|
||||
|
||||
db.AssertExistsAndLoadBean(t, &Reaction{Type: "heart", UserID: user1.ID, IssueID: issue1.ID, CommentID: comment1.ID})
|
||||
unittest.AssertExistsAndLoadBean(t, &Reaction{Type: "heart", UserID: user1.ID, IssueID: issue1.ID, CommentID: comment1.ID})
|
||||
}
|
||||
|
||||
func TestIssueCommentDeleteReaction(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
user1 := db.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
|
||||
user2 := db.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
|
||||
user3 := db.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
|
||||
user4 := db.AssertExistsAndLoadBean(t, &User{ID: 4}).(*User)
|
||||
user1 := unittest.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
|
||||
user2 := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
|
||||
user3 := unittest.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
|
||||
user4 := unittest.AssertExistsAndLoadBean(t, &User{ID: 4}).(*User)
|
||||
|
||||
issue1 := db.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
|
||||
repo1 := db.AssertExistsAndLoadBean(t, &Repository{ID: issue1.RepoID}).(*Repository)
|
||||
issue1 := unittest.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
|
||||
repo1 := unittest.AssertExistsAndLoadBean(t, &Repository{ID: issue1.RepoID}).(*Repository)
|
||||
|
||||
comment1 := db.AssertExistsAndLoadBean(t, &Comment{ID: 1}).(*Comment)
|
||||
comment1 := unittest.AssertExistsAndLoadBean(t, &Comment{ID: 1}).(*Comment)
|
||||
|
||||
addReaction(t, user1, issue1, comment1, "heart")
|
||||
addReaction(t, user2, issue1, comment1, "heart")
|
||||
@@ -155,14 +155,14 @@ func TestIssueCommentDeleteReaction(t *testing.T) {
|
||||
func TestIssueCommentReactionCount(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
user1 := db.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
|
||||
user1 := unittest.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
|
||||
|
||||
issue1 := db.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
|
||||
issue1 := unittest.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
|
||||
|
||||
comment1 := db.AssertExistsAndLoadBean(t, &Comment{ID: 1}).(*Comment)
|
||||
comment1 := unittest.AssertExistsAndLoadBean(t, &Comment{ID: 1}).(*Comment)
|
||||
|
||||
addReaction(t, user1, issue1, comment1, "heart")
|
||||
assert.NoError(t, DeleteCommentReaction(user1, issue1, comment1, "heart"))
|
||||
|
||||
db.AssertNotExistsBean(t, &Reaction{Type: "heart", UserID: user1.ID, IssueID: issue1.ID, CommentID: comment1.ID})
|
||||
unittest.AssertNotExistsBean(t, &Reaction{Type: "heart", UserID: user1.ID, IssueID: issue1.ID, CommentID: comment1.ID})
|
||||
}
|
||||
|
Reference in New Issue
Block a user