diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2021-11-16 16:53:21 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-16 16:53:21 +0800 |
commit | 81926d61db3dac223a75ea49eab893b25a089587 (patch) | |
tree | 627d2f19a008089f3a688e9a94a2cc8d2017afe2 /integrations/api_comment_test.go | |
parent | 23bd7b1211a80aa3b0dcb60ec4a1c0089ff28dd4 (diff) | |
download | gitea-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 'integrations/api_comment_test.go')
-rw-r--r-- | integrations/api_comment_test.go | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/integrations/api_comment_test.go b/integrations/api_comment_test.go index a5513af6e3..6f8c5a85bd 100644 --- a/integrations/api_comment_test.go +++ b/integrations/api_comment_test.go @@ -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}) } |