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 -12
View File
@@ -45,8 +45,7 @@ func TestAPILFSLocksNotLogin(t *testing.T) {
req := NewRequestf(t, "GET", "/%s/%s.git/info/lfs/locks", user.Name, repo.Name)
req.Header.Set("Accept", lfs.MediaType)
resp := MakeRequest(t, req, http.StatusUnauthorized)
var lfsLockError api.LFSLockError
DecodeJSON(t, resp, &lfsLockError)
lfsLockError := DecodeJSON(t, resp, &api.LFSLockError{})
assert.Equal(t, "You must have pull access to list locks", lfsLockError.Message)
}
@@ -109,8 +108,7 @@ func TestAPILFSLocksLogged(t *testing.T) {
req.Header.Set("Content-Type", lfs.MediaType)
resp := session.MakeRequest(t, req, test.httpResult)
if len(test.addTime) > 0 {
var lfsLock api.LFSLockResponse
DecodeJSON(t, resp, &lfsLock)
lfsLock := DecodeJSON(t, resp, &api.LFSLockResponse{})
assert.Equal(t, test.user.Name, lfsLock.Lock.Owner.Name)
assert.Equal(t, lfsLock.Lock.LockedAt.Format(time.RFC3339), lfsLock.Lock.LockedAt.Format(time.RFC3339Nano)) // locked at should be rounded to second
for _, id := range test.addTime {
@@ -125,8 +123,7 @@ func TestAPILFSLocksLogged(t *testing.T) {
req := NewRequestf(t, "GET", "/%s.git/info/lfs/locks", test.repo.FullName())
req.Header.Set("Accept", lfs.AcceptHeader)
resp := session.MakeRequest(t, req, http.StatusOK)
var lfsLocks api.LFSLockList
DecodeJSON(t, resp, &lfsLocks)
lfsLocks := DecodeJSON(t, resp, &api.LFSLockList{})
assert.Len(t, lfsLocks.Locks, test.totalCount)
for i, lock := range lfsLocks.Locks {
assert.Equal(t, test.locksOwners[i].Name, lock.Owner.Name)
@@ -138,8 +135,7 @@ func TestAPILFSLocksLogged(t *testing.T) {
req.Header.Set("Accept", lfs.AcceptHeader)
req.Header.Set("Content-Type", lfs.MediaType)
resp = session.MakeRequest(t, req, http.StatusOK)
var lfsLocksVerify api.LFSLockListVerify
DecodeJSON(t, resp, &lfsLocksVerify)
lfsLocksVerify := DecodeJSON(t, resp, &api.LFSLockListVerify{})
assert.Len(t, lfsLocksVerify.Ours, test.oursCount)
assert.Len(t, lfsLocksVerify.Theirs, test.theirsCount)
for _, lock := range lfsLocksVerify.Ours {
@@ -162,8 +158,7 @@ func TestAPILFSLocksLogged(t *testing.T) {
req.Header.Set("Accept", lfs.AcceptHeader)
req.Header.Set("Content-Type", lfs.MediaType)
resp := session.MakeRequest(t, req, http.StatusOK)
var lfsLockRep api.LFSLockResponse
DecodeJSON(t, resp, &lfsLockRep)
lfsLockRep := DecodeJSON(t, resp, &api.LFSLockResponse{})
assert.Equal(t, test.lockID, lfsLockRep.Lock.ID)
assert.Equal(t, test.user.Name, lfsLockRep.Lock.Owner.Name)
}
@@ -174,8 +169,7 @@ func TestAPILFSLocksLogged(t *testing.T) {
req := NewRequestf(t, "GET", "/%s.git/info/lfs/locks", test.repo.FullName())
req.Header.Set("Accept", lfs.AcceptHeader)
resp := session.MakeRequest(t, req, http.StatusOK)
var lfsLocks api.LFSLockList
DecodeJSON(t, resp, &lfsLocks)
lfsLocks := DecodeJSON(t, resp, &api.LFSLockList{})
assert.Empty(t, lfsLocks.Locks)
}
}