Some checks failed
Build and Release / Create Release (push) Successful in 0s
Trigger Vault Plugin Rebuild / Trigger Vault Rebuild (push) Successful in 0s
Build and Release / Integration Tests (PostgreSQL) (push) Successful in 2m48s
Build and Release / Lint (push) Failing after 5m2s
Build and Release / Build Binaries (amd64, windows, windows-latest) (push) Has been skipped
Build and Release / Build Binaries (amd64, darwin, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (amd64, linux, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (arm64, darwin, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (arm64, linux, linux-latest) (push) Has been skipped
Build and Release / Unit Tests (push) Successful in 5m37s
Go's semantic import versioning requires v2+ modules to include the major version in the module path. This enables using proper version tags (v3.x.x) instead of pseudo-versions. Updated module path: code.gitcaddy.com/server/v3
51 lines
1.9 KiB
Go
51 lines
1.9 KiB
Go
// Copyright 2019 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package context
|
|
|
|
import (
|
|
"net/url"
|
|
"strconv"
|
|
"testing"
|
|
|
|
"code.gitcaddy.com/server/v3/modules/setting"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestGenAPILinks(t *testing.T) {
|
|
setting.AppURL = "http://localhost:3000/"
|
|
kases := map[string][]string{
|
|
"api/v1/repos/jerrykan/example-repo/issues?state=all": {
|
|
`<http://localhost:3000/api/v1/repos/jerrykan/example-repo/issues?page=2&state=all>; rel="next"`,
|
|
`<http://localhost:3000/api/v1/repos/jerrykan/example-repo/issues?page=5&state=all>; rel="last"`,
|
|
},
|
|
"api/v1/repos/jerrykan/example-repo/issues?state=all&page=1": {
|
|
`<http://localhost:3000/api/v1/repos/jerrykan/example-repo/issues?page=2&state=all>; rel="next"`,
|
|
`<http://localhost:3000/api/v1/repos/jerrykan/example-repo/issues?page=5&state=all>; rel="last"`,
|
|
},
|
|
"api/v1/repos/jerrykan/example-repo/issues?state=all&page=2": {
|
|
`<http://localhost:3000/api/v1/repos/jerrykan/example-repo/issues?page=3&state=all>; rel="next"`,
|
|
`<http://localhost:3000/api/v1/repos/jerrykan/example-repo/issues?page=5&state=all>; rel="last"`,
|
|
`<http://localhost:3000/api/v1/repos/jerrykan/example-repo/issues?page=1&state=all>; rel="first"`,
|
|
`<http://localhost:3000/api/v1/repos/jerrykan/example-repo/issues?page=1&state=all>; rel="prev"`,
|
|
},
|
|
"api/v1/repos/jerrykan/example-repo/issues?state=all&page=5": {
|
|
`<http://localhost:3000/api/v1/repos/jerrykan/example-repo/issues?page=1&state=all>; rel="first"`,
|
|
`<http://localhost:3000/api/v1/repos/jerrykan/example-repo/issues?page=4&state=all>; rel="prev"`,
|
|
},
|
|
}
|
|
|
|
for req, response := range kases {
|
|
u, err := url.Parse(setting.AppURL + req)
|
|
assert.NoError(t, err)
|
|
|
|
p := u.Query().Get("page")
|
|
curPage, _ := strconv.Atoi(p)
|
|
|
|
links := genAPILinks(u, 100, 20, curPage)
|
|
|
|
assert.Equal(t, links, response)
|
|
}
|
|
}
|