mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-09-25 04:05:55 +00:00
fix(api): set default pagination and Link header for repoListTags
(#9201)
- Set default pagination, so the API allows cases like `?limit=1`. - Set the Link header when there are more items, but not shown because of pagination. - Resolves forgejo/forgejo#8828 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9201 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: deadkittens <montage_inches78@icloud.com> Co-committed-by: deadkittens <montage_inches78@icloud.com>
This commit is contained in:
parent
1d8fb306d7
commit
6d5bdce9dd
3 changed files with 74 additions and 1 deletions
|
@ -121,3 +121,36 @@ func TestAPIGetTagArchiveDownloadCount(t *testing.T) {
|
|||
assert.Equal(t, int64(1), tagInfo.ArchiveDownloadCount.TarGz)
|
||||
assert.Equal(t, int64(0), tagInfo.ArchiveDownloadCount.Zip)
|
||||
}
|
||||
|
||||
func TestAPIGetTagsPaginated(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
// Login as User2.
|
||||
session := loginUser(t, user.Name)
|
||||
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
|
||||
|
||||
repoName := "repo1"
|
||||
expectedTagName := "TagDownloadCount"
|
||||
|
||||
for i := range 5 {
|
||||
createNewTagUsingAPI(t, token, user.Name, repoName, expectedTagName+fmt.Sprintf("%d", i), "", "")
|
||||
}
|
||||
|
||||
// List tags with pagination
|
||||
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/tags?limit=1", user.Name, repoName).
|
||||
AddTokenAuth(token)
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
var tags []*api.Tag
|
||||
DecodeJSON(t, resp, &tags)
|
||||
|
||||
assert.Len(t, tags, 1)
|
||||
|
||||
assert.Equal(t, fmt.Sprintf("%s%d", expectedTagName, 0), tags[0].Name)
|
||||
|
||||
// Check if Link header is present for pagination
|
||||
link := resp.Header().Get("Link")
|
||||
assert.NotEmpty(t, link, "Link header should be set for paginated responses")
|
||||
assert.Contains(t, link, "rel=\"next\"")
|
||||
assert.Contains(t, link, "page=2")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue