snapshot of https://github.com/go-gitea/gitea.git (main, 2026-09-15; blobs > 131072B omitted)
Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
This commit is contained in:
14
models/db/paginator/main_test.go
Normal file
14
models/db/paginator/main_test.go
Normal file
@@ -0,0 +1,14 @@
|
||||
// Copyright 2021 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package paginator
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gitea.dev/models/unittest"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m)
|
||||
}
|
||||
7
models/db/paginator/paginator.go
Normal file
7
models/db/paginator/paginator.go
Normal file
@@ -0,0 +1,7 @@
|
||||
// Copyright 2021 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package paginator
|
||||
|
||||
// dummy only. in the future, the models/db/list_options.go should be moved here to decouple from db package
|
||||
// otherwise the unit test will cause cycle import
|
||||
59
models/db/paginator/paginator_test.go
Normal file
59
models/db/paginator/paginator_test.go
Normal file
@@ -0,0 +1,59 @@
|
||||
// Copyright 2021 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package paginator
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gitea.dev/models/db"
|
||||
"gitea.dev/modules/setting"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestPaginator(t *testing.T) {
|
||||
cases := []struct {
|
||||
db.Paginator
|
||||
Skip int
|
||||
Take int
|
||||
Start int
|
||||
End int
|
||||
}{
|
||||
{
|
||||
Paginator: &db.ListOptions{Page: -1, PageSize: -1},
|
||||
Skip: 0,
|
||||
Take: setting.API.DefaultPagingNum,
|
||||
Start: 0,
|
||||
End: setting.API.DefaultPagingNum,
|
||||
},
|
||||
{
|
||||
Paginator: &db.ListOptions{Page: 2, PageSize: 10},
|
||||
Skip: 10,
|
||||
Take: 10,
|
||||
Start: 10,
|
||||
End: 20,
|
||||
},
|
||||
{
|
||||
Paginator: db.NewAbsoluteListOptions(-1, -1),
|
||||
Skip: 0,
|
||||
Take: setting.API.DefaultPagingNum,
|
||||
Start: 0,
|
||||
End: setting.API.DefaultPagingNum,
|
||||
},
|
||||
{
|
||||
Paginator: db.NewAbsoluteListOptions(2, 10),
|
||||
Skip: 2,
|
||||
Take: 10,
|
||||
Start: 2,
|
||||
End: 12,
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
skip, take := c.Paginator.GetSkipTake()
|
||||
|
||||
assert.Equal(t, c.Skip, skip)
|
||||
assert.Equal(t, c.Take, take)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user