@@ -11,7 +11,7 @@ import (
1111 "testing"
1212
1313 "code.gitea.io/gitea/models"
14- "code.gitea.io/gitea/models/db "
14+ "code.gitea.io/gitea/models/unittest "
1515 "code.gitea.io/gitea/modules/convert"
1616 api "code.gitea.io/gitea/modules/structs"
1717
@@ -21,11 +21,11 @@ import (
2121func TestAPIListRepoComments (t * testing.T ) {
2222 defer prepareTestEnv (t )()
2323
24- comment := db .AssertExistsAndLoadBean (t , & models.Comment {},
25- db .Cond ("type = ?" , models .CommentTypeComment )).(* models.Comment )
26- issue := db .AssertExistsAndLoadBean (t , & models.Issue {ID : comment .IssueID }).(* models.Issue )
27- repo := db .AssertExistsAndLoadBean (t , & models.Repository {ID : issue .RepoID }).(* models.Repository )
28- repoOwner := db .AssertExistsAndLoadBean (t , & models.User {ID : repo .OwnerID }).(* models.User )
24+ comment := unittest .AssertExistsAndLoadBean (t , & models.Comment {},
25+ unittest .Cond ("type = ?" , models .CommentTypeComment )).(* models.Comment )
26+ issue := unittest .AssertExistsAndLoadBean (t , & models.Issue {ID : comment .IssueID }).(* models.Issue )
27+ repo := unittest .AssertExistsAndLoadBean (t , & models.Repository {ID : issue .RepoID }).(* models.Repository )
28+ repoOwner := unittest .AssertExistsAndLoadBean (t , & models.User {ID : repo .OwnerID }).(* models.User )
2929
3030 session := loginUser (t , repoOwner .Name )
3131 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) {
3737 assert .Len (t , apiComments , 2 )
3838 for _ , apiComment := range apiComments {
3939 c := & models.Comment {ID : apiComment .ID }
40- db .AssertExistsAndLoadBean (t , c ,
41- db .Cond ("type = ?" , models .CommentTypeComment ))
42- db .AssertExistsAndLoadBean (t , & models.Issue {ID : c .IssueID , RepoID : repo .ID })
40+ unittest .AssertExistsAndLoadBean (t , c ,
41+ unittest .Cond ("type = ?" , models .CommentTypeComment ))
42+ unittest .AssertExistsAndLoadBean (t , & models.Issue {ID : c .IssueID , RepoID : repo .ID })
4343 }
4444
4545 //test before and since filters
@@ -67,11 +67,11 @@ func TestAPIListRepoComments(t *testing.T) {
6767func TestAPIListIssueComments (t * testing.T ) {
6868 defer prepareTestEnv (t )()
6969
70- comment := db .AssertExistsAndLoadBean (t , & models.Comment {},
71- db .Cond ("type = ?" , models .CommentTypeComment )).(* models.Comment )
72- issue := db .AssertExistsAndLoadBean (t , & models.Issue {ID : comment .IssueID }).(* models.Issue )
73- repo := db .AssertExistsAndLoadBean (t , & models.Repository {ID : issue .RepoID }).(* models.Repository )
74- repoOwner := db .AssertExistsAndLoadBean (t , & models.User {ID : repo .OwnerID }).(* models.User )
70+ comment := unittest .AssertExistsAndLoadBean (t , & models.Comment {},
71+ unittest .Cond ("type = ?" , models .CommentTypeComment )).(* models.Comment )
72+ issue := unittest .AssertExistsAndLoadBean (t , & models.Issue {ID : comment .IssueID }).(* models.Issue )
73+ repo := unittest .AssertExistsAndLoadBean (t , & models.Repository {ID : issue .RepoID }).(* models.Repository )
74+ repoOwner := unittest .AssertExistsAndLoadBean (t , & models.User {ID : repo .OwnerID }).(* models.User )
7575
7676 session := loginUser (t , repoOwner .Name )
7777 req := NewRequestf (t , "GET" , "/api/v1/repos/%s/%s/issues/%d/comments" ,
@@ -80,18 +80,18 @@ func TestAPIListIssueComments(t *testing.T) {
8080
8181 var comments []* api.Comment
8282 DecodeJSON (t , resp , & comments )
83- expectedCount := db .GetCount (t , & models.Comment {IssueID : issue .ID },
84- db .Cond ("type = ?" , models .CommentTypeComment ))
83+ expectedCount := unittest .GetCount (t , & models.Comment {IssueID : issue .ID },
84+ unittest .Cond ("type = ?" , models .CommentTypeComment ))
8585 assert .EqualValues (t , expectedCount , len (comments ))
8686}
8787
8888func TestAPICreateComment (t * testing.T ) {
8989 defer prepareTestEnv (t )()
9090 const commentBody = "Comment body"
9191
92- issue := db .AssertExistsAndLoadBean (t , & models.Issue {}).(* models.Issue )
93- repo := db .AssertExistsAndLoadBean (t , & models.Repository {ID : issue .RepoID }).(* models.Repository )
94- repoOwner := db .AssertExistsAndLoadBean (t , & models.User {ID : repo .OwnerID }).(* models.User )
92+ issue := unittest .AssertExistsAndLoadBean (t , & models.Issue {}).(* models.Issue )
93+ repo := unittest .AssertExistsAndLoadBean (t , & models.Repository {ID : issue .RepoID }).(* models.Repository )
94+ repoOwner := unittest .AssertExistsAndLoadBean (t , & models.User {ID : repo .OwnerID }).(* models.User )
9595
9696 session := loginUser (t , repoOwner .Name )
9797 token := getTokenForLoggedInUser (t , session )
@@ -105,16 +105,16 @@ func TestAPICreateComment(t *testing.T) {
105105 var updatedComment api.Comment
106106 DecodeJSON (t , resp , & updatedComment )
107107 assert .EqualValues (t , commentBody , updatedComment .Body )
108- db .AssertExistsAndLoadBean (t , & models.Comment {ID : updatedComment .ID , IssueID : issue .ID , Content : commentBody })
108+ unittest .AssertExistsAndLoadBean (t , & models.Comment {ID : updatedComment .ID , IssueID : issue .ID , Content : commentBody })
109109}
110110
111111func TestAPIGetComment (t * testing.T ) {
112112 defer prepareTestEnv (t )()
113113
114- comment := db .AssertExistsAndLoadBean (t , & models.Comment {ID : 2 }).(* models.Comment )
114+ comment := unittest .AssertExistsAndLoadBean (t , & models.Comment {ID : 2 }).(* models.Comment )
115115 assert .NoError (t , comment .LoadIssue ())
116- repo := db .AssertExistsAndLoadBean (t , & models.Repository {ID : comment .Issue .RepoID }).(* models.Repository )
117- repoOwner := db .AssertExistsAndLoadBean (t , & models.User {ID : repo .OwnerID }).(* models.User )
116+ repo := unittest .AssertExistsAndLoadBean (t , & models.Repository {ID : comment .Issue .RepoID }).(* models.Repository )
117+ repoOwner := unittest .AssertExistsAndLoadBean (t , & models.User {ID : repo .OwnerID }).(* models.User )
118118
119119 session := loginUser (t , repoOwner .Name )
120120 token := getTokenForLoggedInUser (t , session )
@@ -139,11 +139,11 @@ func TestAPIEditComment(t *testing.T) {
139139 defer prepareTestEnv (t )()
140140 const newCommentBody = "This is the new comment body"
141141
142- comment := db .AssertExistsAndLoadBean (t , & models.Comment {},
143- db .Cond ("type = ?" , models .CommentTypeComment )).(* models.Comment )
144- issue := db .AssertExistsAndLoadBean (t , & models.Issue {ID : comment .IssueID }).(* models.Issue )
145- repo := db .AssertExistsAndLoadBean (t , & models.Repository {ID : issue .RepoID }).(* models.Repository )
146- repoOwner := db .AssertExistsAndLoadBean (t , & models.User {ID : repo .OwnerID }).(* models.User )
142+ comment := unittest .AssertExistsAndLoadBean (t , & models.Comment {},
143+ unittest .Cond ("type = ?" , models .CommentTypeComment )).(* models.Comment )
144+ issue := unittest .AssertExistsAndLoadBean (t , & models.Issue {ID : comment .IssueID }).(* models.Issue )
145+ repo := unittest .AssertExistsAndLoadBean (t , & models.Repository {ID : issue .RepoID }).(* models.Repository )
146+ repoOwner := unittest .AssertExistsAndLoadBean (t , & models.User {ID : repo .OwnerID }).(* models.User )
147147
148148 session := loginUser (t , repoOwner .Name )
149149 token := getTokenForLoggedInUser (t , session )
@@ -158,23 +158,23 @@ func TestAPIEditComment(t *testing.T) {
158158 DecodeJSON (t , resp , & updatedComment )
159159 assert .EqualValues (t , comment .ID , updatedComment .ID )
160160 assert .EqualValues (t , newCommentBody , updatedComment .Body )
161- db .AssertExistsAndLoadBean (t , & models.Comment {ID : comment .ID , IssueID : issue .ID , Content : newCommentBody })
161+ unittest .AssertExistsAndLoadBean (t , & models.Comment {ID : comment .ID , IssueID : issue .ID , Content : newCommentBody })
162162}
163163
164164func TestAPIDeleteComment (t * testing.T ) {
165165 defer prepareTestEnv (t )()
166166
167- comment := db .AssertExistsAndLoadBean (t , & models.Comment {},
168- db .Cond ("type = ?" , models .CommentTypeComment )).(* models.Comment )
169- issue := db .AssertExistsAndLoadBean (t , & models.Issue {ID : comment .IssueID }).(* models.Issue )
170- repo := db .AssertExistsAndLoadBean (t , & models.Repository {ID : issue .RepoID }).(* models.Repository )
171- repoOwner := db .AssertExistsAndLoadBean (t , & models.User {ID : repo .OwnerID }).(* models.User )
167+ comment := unittest .AssertExistsAndLoadBean (t , & models.Comment {},
168+ unittest .Cond ("type = ?" , models .CommentTypeComment )).(* models.Comment )
169+ issue := unittest .AssertExistsAndLoadBean (t , & models.Issue {ID : comment .IssueID }).(* models.Issue )
170+ repo := unittest .AssertExistsAndLoadBean (t , & models.Repository {ID : issue .RepoID }).(* models.Repository )
171+ repoOwner := unittest .AssertExistsAndLoadBean (t , & models.User {ID : repo .OwnerID }).(* models.User )
172172
173173 session := loginUser (t , repoOwner .Name )
174174 token := getTokenForLoggedInUser (t , session )
175175 req := NewRequestf (t , "DELETE" , "/api/v1/repos/%s/%s/issues/comments/%d?token=%s" ,
176176 repoOwner .Name , repo .Name , comment .ID , token )
177177 session .MakeRequest (t , req , http .StatusNoContent )
178178
179- db .AssertNotExistsBean (t , & models.Comment {ID : comment .ID })
179+ unittest .AssertNotExistsBean (t , & models.Comment {ID : comment .ID })
180180}
0 commit comments