Refactor integration test DecodeJSON calls to use generic return value (#37432)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: wxiaoguang <2114189+wxiaoguang@users.noreply.github.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Copilot
2026-04-26 14:57:07 +00:00
committed by GitHub
parent 99cd4f6b22
commit 2671b997f2
105 changed files with 569 additions and 930 deletions
+9 -16
View File
@@ -34,8 +34,7 @@ func TestAPIListRepoComments(t *testing.T) {
req := NewRequest(t, "GET", link.String())
resp := MakeRequest(t, req, http.StatusOK)
var apiComments []*api.Comment
DecodeJSON(t, resp, &apiComments)
apiComments := DecodeJSON(t, resp, []*api.Comment{})
assert.Len(t, apiComments, 2)
for _, apiComment := range apiComments {
c := &issues_model.Comment{ID: apiComment.ID}
@@ -52,7 +51,7 @@ func TestAPIListRepoComments(t *testing.T) {
link.RawQuery = query.Encode()
req = NewRequest(t, "GET", link.String())
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiComments)
apiComments = DecodeJSON(t, resp, []*api.Comment{})
assert.Len(t, apiComments, 1)
assert.EqualValues(t, 2, apiComments[0].ID)
@@ -61,7 +60,7 @@ func TestAPIListRepoComments(t *testing.T) {
link.RawQuery = query.Encode()
req = NewRequest(t, "GET", link.String())
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiComments)
apiComments = DecodeJSON(t, resp, []*api.Comment{})
assert.Len(t, apiComments, 1)
assert.EqualValues(t, 3, apiComments[0].ID)
}
@@ -80,8 +79,7 @@ func TestAPIListIssueComments(t *testing.T) {
AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusOK)
var comments []*api.Comment
DecodeJSON(t, resp, &comments)
comments := DecodeJSON(t, resp, []*api.Comment{})
expectedCount := unittest.GetCount(t, &issues_model.Comment{IssueID: issue.ID},
unittest.Cond("type = ?", issues_model.CommentTypeComment))
assert.Len(t, comments, expectedCount)
@@ -103,8 +101,7 @@ func TestAPICreateComment(t *testing.T) {
}).AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusCreated)
var updatedComment api.Comment
DecodeJSON(t, resp, &updatedComment)
updatedComment := DecodeJSON(t, resp, &api.Comment{})
assert.Equal(t, commentBody, updatedComment.Body)
unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: updatedComment.ID, IssueID: issue.ID, Content: commentBody})
@@ -150,8 +147,7 @@ func TestAPIGetComment(t *testing.T) {
AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusOK)
var apiComment api.Comment
DecodeJSON(t, resp, &apiComment)
apiComment := DecodeJSON(t, resp, &api.Comment{})
assert.NoError(t, comment.LoadPoster(t.Context()))
expect := convert.ToAPIComment(t.Context(), repo, comment)
@@ -186,8 +182,7 @@ func TestAPIGetSystemUserComment(t *testing.T) {
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/comments/%d", repoOwner.Name, repo.Name, comment.ID)
resp := MakeRequest(t, req, http.StatusOK)
var apiComment api.Comment
DecodeJSON(t, resp, &apiComment)
apiComment := DecodeJSON(t, resp, &api.Comment{})
if assert.NotNil(t, apiComment.Poster) {
if assert.Equal(t, systemUser.ID, apiComment.Poster.ID) {
@@ -230,8 +225,7 @@ func TestAPIEditComment(t *testing.T) {
}).AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusOK)
var updatedComment api.Comment
DecodeJSON(t, resp, &updatedComment)
updatedComment := DecodeJSON(t, resp, &api.Comment{})
assert.Equal(t, comment.ID, updatedComment.ID)
assert.Equal(t, newCommentBody, updatedComment.Body)
unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: comment.ID, IssueID: issue.ID, Content: newCommentBody})
@@ -278,8 +272,7 @@ func TestAPIListIssueTimeline(t *testing.T) {
// check if lens of list returned by API and
// lists extracted directly from DB are the same
var comments []*api.TimelineComment
DecodeJSON(t, resp, &comments)
comments := DecodeJSON(t, resp, []*api.TimelineComment{})
expectedCount := unittest.GetCount(t, &issues_model.Comment{IssueID: issue.ID})
assert.Len(t, comments, expectedCount)
}