Decouple unit test, remove intermediate unittestbridge
package (#17662)
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
parent
23bd7b1211
commit
81926d61db
151 changed files with 1719 additions and 1781 deletions
|
@ -11,7 +11,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/convert"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
|
||||
|
@ -21,11 +21,11 @@ import (
|
|||
func TestAPIListRepoComments(t *testing.T) {
|
||||
defer prepareTestEnv(t)()
|
||||
|
||||
comment := db.AssertExistsAndLoadBean(t, &models.Comment{},
|
||||
db.Cond("type = ?", models.CommentTypeComment)).(*models.Comment)
|
||||
issue := db.AssertExistsAndLoadBean(t, &models.Issue{ID: comment.IssueID}).(*models.Issue)
|
||||
repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: issue.RepoID}).(*models.Repository)
|
||||
repoOwner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
|
||||
comment := unittest.AssertExistsAndLoadBean(t, &models.Comment{},
|
||||
unittest.Cond("type = ?", models.CommentTypeComment)).(*models.Comment)
|
||||
issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: comment.IssueID}).(*models.Issue)
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: issue.RepoID}).(*models.Repository)
|
||||
repoOwner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
|
||||
|
||||
session := loginUser(t, repoOwner.Name)
|
||||
link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/issues/comments", repoOwner.Name, repo.Name))
|
||||
|
@ -37,9 +37,9 @@ func TestAPIListRepoComments(t *testing.T) {
|
|||
assert.Len(t, apiComments, 2)
|
||||
for _, apiComment := range apiComments {
|
||||
c := &models.Comment{ID: apiComment.ID}
|
||||
db.AssertExistsAndLoadBean(t, c,
|
||||
db.Cond("type = ?", models.CommentTypeComment))
|
||||
db.AssertExistsAndLoadBean(t, &models.Issue{ID: c.IssueID, RepoID: repo.ID})
|
||||
unittest.AssertExistsAndLoadBean(t, c,
|
||||
unittest.Cond("type = ?", models.CommentTypeComment))
|
||||
unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: c.IssueID, RepoID: repo.ID})
|
||||
}
|
||||
|
||||
//test before and since filters
|
||||
|
@ -67,11 +67,11 @@ func TestAPIListRepoComments(t *testing.T) {
|
|||
func TestAPIListIssueComments(t *testing.T) {
|
||||
defer prepareTestEnv(t)()
|
||||
|
||||
comment := db.AssertExistsAndLoadBean(t, &models.Comment{},
|
||||
db.Cond("type = ?", models.CommentTypeComment)).(*models.Comment)
|
||||
issue := db.AssertExistsAndLoadBean(t, &models.Issue{ID: comment.IssueID}).(*models.Issue)
|
||||
repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: issue.RepoID}).(*models.Repository)
|
||||
repoOwner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
|
||||
comment := unittest.AssertExistsAndLoadBean(t, &models.Comment{},
|
||||
unittest.Cond("type = ?", models.CommentTypeComment)).(*models.Comment)
|
||||
issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: comment.IssueID}).(*models.Issue)
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: issue.RepoID}).(*models.Repository)
|
||||
repoOwner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
|
||||
|
||||
session := loginUser(t, repoOwner.Name)
|
||||
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/%d/comments",
|
||||
|
@ -80,8 +80,8 @@ func TestAPIListIssueComments(t *testing.T) {
|
|||
|
||||
var comments []*api.Comment
|
||||
DecodeJSON(t, resp, &comments)
|
||||
expectedCount := db.GetCount(t, &models.Comment{IssueID: issue.ID},
|
||||
db.Cond("type = ?", models.CommentTypeComment))
|
||||
expectedCount := unittest.GetCount(t, &models.Comment{IssueID: issue.ID},
|
||||
unittest.Cond("type = ?", models.CommentTypeComment))
|
||||
assert.EqualValues(t, expectedCount, len(comments))
|
||||
}
|
||||
|
||||
|
@ -89,9 +89,9 @@ func TestAPICreateComment(t *testing.T) {
|
|||
defer prepareTestEnv(t)()
|
||||
const commentBody = "Comment body"
|
||||
|
||||
issue := db.AssertExistsAndLoadBean(t, &models.Issue{}).(*models.Issue)
|
||||
repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: issue.RepoID}).(*models.Repository)
|
||||
repoOwner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
|
||||
issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{}).(*models.Issue)
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: issue.RepoID}).(*models.Repository)
|
||||
repoOwner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
|
||||
|
||||
session := loginUser(t, repoOwner.Name)
|
||||
token := getTokenForLoggedInUser(t, session)
|
||||
|
@ -105,16 +105,16 @@ func TestAPICreateComment(t *testing.T) {
|
|||
var updatedComment api.Comment
|
||||
DecodeJSON(t, resp, &updatedComment)
|
||||
assert.EqualValues(t, commentBody, updatedComment.Body)
|
||||
db.AssertExistsAndLoadBean(t, &models.Comment{ID: updatedComment.ID, IssueID: issue.ID, Content: commentBody})
|
||||
unittest.AssertExistsAndLoadBean(t, &models.Comment{ID: updatedComment.ID, IssueID: issue.ID, Content: commentBody})
|
||||
}
|
||||
|
||||
func TestAPIGetComment(t *testing.T) {
|
||||
defer prepareTestEnv(t)()
|
||||
|
||||
comment := db.AssertExistsAndLoadBean(t, &models.Comment{ID: 2}).(*models.Comment)
|
||||
comment := unittest.AssertExistsAndLoadBean(t, &models.Comment{ID: 2}).(*models.Comment)
|
||||
assert.NoError(t, comment.LoadIssue())
|
||||
repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: comment.Issue.RepoID}).(*models.Repository)
|
||||
repoOwner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: comment.Issue.RepoID}).(*models.Repository)
|
||||
repoOwner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
|
||||
|
||||
session := loginUser(t, repoOwner.Name)
|
||||
token := getTokenForLoggedInUser(t, session)
|
||||
|
@ -139,11 +139,11 @@ func TestAPIEditComment(t *testing.T) {
|
|||
defer prepareTestEnv(t)()
|
||||
const newCommentBody = "This is the new comment body"
|
||||
|
||||
comment := db.AssertExistsAndLoadBean(t, &models.Comment{},
|
||||
db.Cond("type = ?", models.CommentTypeComment)).(*models.Comment)
|
||||
issue := db.AssertExistsAndLoadBean(t, &models.Issue{ID: comment.IssueID}).(*models.Issue)
|
||||
repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: issue.RepoID}).(*models.Repository)
|
||||
repoOwner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
|
||||
comment := unittest.AssertExistsAndLoadBean(t, &models.Comment{},
|
||||
unittest.Cond("type = ?", models.CommentTypeComment)).(*models.Comment)
|
||||
issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: comment.IssueID}).(*models.Issue)
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: issue.RepoID}).(*models.Repository)
|
||||
repoOwner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
|
||||
|
||||
session := loginUser(t, repoOwner.Name)
|
||||
token := getTokenForLoggedInUser(t, session)
|
||||
|
@ -158,17 +158,17 @@ func TestAPIEditComment(t *testing.T) {
|
|||
DecodeJSON(t, resp, &updatedComment)
|
||||
assert.EqualValues(t, comment.ID, updatedComment.ID)
|
||||
assert.EqualValues(t, newCommentBody, updatedComment.Body)
|
||||
db.AssertExistsAndLoadBean(t, &models.Comment{ID: comment.ID, IssueID: issue.ID, Content: newCommentBody})
|
||||
unittest.AssertExistsAndLoadBean(t, &models.Comment{ID: comment.ID, IssueID: issue.ID, Content: newCommentBody})
|
||||
}
|
||||
|
||||
func TestAPIDeleteComment(t *testing.T) {
|
||||
defer prepareTestEnv(t)()
|
||||
|
||||
comment := db.AssertExistsAndLoadBean(t, &models.Comment{},
|
||||
db.Cond("type = ?", models.CommentTypeComment)).(*models.Comment)
|
||||
issue := db.AssertExistsAndLoadBean(t, &models.Issue{ID: comment.IssueID}).(*models.Issue)
|
||||
repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: issue.RepoID}).(*models.Repository)
|
||||
repoOwner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
|
||||
comment := unittest.AssertExistsAndLoadBean(t, &models.Comment{},
|
||||
unittest.Cond("type = ?", models.CommentTypeComment)).(*models.Comment)
|
||||
issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: comment.IssueID}).(*models.Issue)
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: issue.RepoID}).(*models.Repository)
|
||||
repoOwner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
|
||||
|
||||
session := loginUser(t, repoOwner.Name)
|
||||
token := getTokenForLoggedInUser(t, session)
|
||||
|
@ -176,5 +176,5 @@ func TestAPIDeleteComment(t *testing.T) {
|
|||
repoOwner.Name, repo.Name, comment.ID, token)
|
||||
session.MakeRequest(t, req, http.StatusNoContent)
|
||||
|
||||
db.AssertNotExistsBean(t, &models.Comment{ID: comment.ID})
|
||||
unittest.AssertNotExistsBean(t, &models.Comment{ID: comment.ID})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue