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
+6 -7
View File
@@ -200,8 +200,7 @@ func TestAPIRepoEdit(t *testing.T) {
req := NewRequestWithJSON(t, "PATCH", fmt.Sprintf("/api/v1/repos/%s/%s", user2.Name, repo1.Name), &repoEditOption).
AddTokenAuth(token2)
resp := MakeRequest(t, req, http.StatusOK)
var repo api.Repository
DecodeJSON(t, resp, &repo)
repo := DecodeJSON(t, resp, &api.Repository{})
assert.NotNil(t, repo)
// check response
assert.Equal(t, *repoEditOption.Name, repo.Name)
@@ -237,7 +236,7 @@ func TestAPIRepoEdit(t *testing.T) {
req = NewRequestWithJSON(t, "PATCH", url, &repoEditOption).
AddTokenAuth(token2)
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &repo)
repo = DecodeJSON(t, resp, &api.Repository{})
assert.NotNil(t, repo)
// check repo1 was written to database
repo1edited = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
@@ -260,7 +259,7 @@ func TestAPIRepoEdit(t *testing.T) {
req = NewRequestWithJSON(t, "PATCH", url, &repoEditOption).
AddTokenAuth(token2)
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &repo)
repo = DecodeJSON(t, resp, &api.Repository{})
assert.NotNil(t, repo)
// check repo1 was written to database
repo1edited = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
@@ -280,7 +279,7 @@ func TestAPIRepoEdit(t *testing.T) {
req = NewRequestWithJSON(t, "PATCH", url, &repoEditOption).
AddTokenAuth(token2)
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &repo)
repo = DecodeJSON(t, resp, &api.Repository{})
assert.NotNil(t, repo)
repo1edited = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
repo1editedOption = getRepoEditOptionFromRepo(repo1edited)
@@ -312,7 +311,7 @@ func TestAPIRepoEdit(t *testing.T) {
req = NewRequestWithJSON(t, "PATCH", url, &repoEditOption).
AddTokenAuth(token2)
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &repo)
repo = DecodeJSON(t, resp, &api.Repository{})
assert.NotNil(t, repo)
// check repo1 was written to database
repo1edited = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
@@ -426,7 +425,7 @@ func TestAPIRepoEdit(t *testing.T) {
DefaultDeleteBranchAfterMerge: &bTrue,
}).AddTokenAuth(token2)
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &repo)
repo = DecodeJSON(t, resp, &api.Repository{})
assert.True(t, repo.DefaultDeleteBranchAfterMerge)
// reset
req = NewRequestWithJSON(t, "PATCH", url, &api.EditRepoOption{