summaryrefslogtreecommitdiffstats
path: root/models/db/paginator
diff options
context:
space:
mode:
authorDaniel Baumann <daniel@debian.org>2024-10-18 20:33:49 +0200
committerDaniel Baumann <daniel@debian.org>2024-12-12 23:57:56 +0100
commite68b9d00a6e05b3a941f63ffb696f91e554ac5ec (patch)
tree97775d6c13b0f416af55314eb6a89ef792474615 /models/db/paginator
parentInitial commit. (diff)
downloadforgejo-e68b9d00a6e05b3a941f63ffb696f91e554ac5ec.tar.xz
forgejo-e68b9d00a6e05b3a941f63ffb696f91e554ac5ec.zip
Adding upstream version 9.0.3.
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to '')
-rw-r--r--models/db/paginator/main_test.go14
-rw-r--r--models/db/paginator/paginator.go7
-rw-r--r--models/db/paginator/paginator_test.go59
3 files changed, 80 insertions, 0 deletions
diff --git a/models/db/paginator/main_test.go b/models/db/paginator/main_test.go
new file mode 100644
index 0000000..47993ae
--- /dev/null
+++ b/models/db/paginator/main_test.go
@@ -0,0 +1,14 @@
+// Copyright 2021 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package paginator
+
+import (
+ "testing"
+
+ "code.gitea.io/gitea/models/unittest"
+)
+
+func TestMain(m *testing.M) {
+ unittest.MainTest(m)
+}
diff --git a/models/db/paginator/paginator.go b/models/db/paginator/paginator.go
new file mode 100644
index 0000000..bcda47d
--- /dev/null
+++ b/models/db/paginator/paginator.go
@@ -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
diff --git a/models/db/paginator/paginator_test.go b/models/db/paginator/paginator_test.go
new file mode 100644
index 0000000..2060221
--- /dev/null
+++ b/models/db/paginator/paginator_test.go
@@ -0,0 +1,59 @@
+// Copyright 2021 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package paginator
+
+import (
+ "testing"
+
+ "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/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)
+ }
+}