Skip to content

Commit 7a37efd

Browse files
committed
test: fix case
1 parent b1db5ba commit 7a37efd

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

modules/indexer/internal/paginator.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func ParsePaginator(listOptions db.ListOptions, max ...int) (int, int) {
2121
if listOptions.IsListAll() {
2222
// It shouldn't happen. In actual usage scenarios, there should not be requests to search all.
2323
// But if it does happen, respect it and return "unlimited".
24+
// And it's also useful for testing.
2425
return 0, unlimited
2526
}
2627

modules/indexer/issues/internal/tests/tests.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"time"
1616

1717
"code.gitea.io/gitea/models/db"
18-
"code.gitea.io/gitea/modules/indexer/issues"
1918
"code.gitea.io/gitea/modules/indexer/issues/internal"
2019
"code.gitea.io/gitea/modules/optional"
2120
"code.gitea.io/gitea/modules/timeutil"
@@ -80,8 +79,8 @@ func TestIndexer(t *testing.T, indexer internal.Indexer) {
8079
}
8180

8281
// test counting
83-
opts := c.SearchOptions.Copy(func(options *issues.SearchOptions) { options.ListOptions = db.ListOptions{PageSize: 0} })
84-
countResult, err := indexer.Search(context.Background(), opts)
82+
c.SearchOptions.ListOptions = db.ListOptions{PageSize: 0}
83+
countResult, err := indexer.Search(context.Background(), c.SearchOptions)
8584
require.NoError(t, err)
8685
assert.Empty(t, countResult.Hits)
8786
assert.Equal(t, result.Total, countResult.Total)
@@ -91,8 +90,12 @@ func TestIndexer(t *testing.T, indexer internal.Indexer) {
9190

9291
var cases = []*testIndexerCase{
9392
{
94-
Name: "default",
95-
SearchOptions: &internal.SearchOptions{},
93+
Name: "default",
94+
SearchOptions: &internal.SearchOptions{
95+
ListOptions: db.ListOptions{
96+
ListAll: true,
97+
},
98+
},
9699
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
97100
assert.Equal(t, len(data), len(result.Hits))
98101
assert.Equal(t, len(data), int(result.Total))
@@ -126,6 +129,9 @@ var cases = []*testIndexerCase{
126129
{ID: 1002, Comments: []string{"hi", "hello world"}},
127130
},
128131
SearchOptions: &internal.SearchOptions{
132+
ListOptions: db.ListOptions{
133+
ListAll: true,
134+
},
129135
Keyword: "hello",
130136
},
131137
ExpectedIDs: []int64{1002, 1001, 1000},
@@ -143,6 +149,9 @@ var cases = []*testIndexerCase{
143149
{ID: 1007, Title: "hello world", RepoID: 5, IsPublic: false},
144150
},
145151
SearchOptions: &internal.SearchOptions{
152+
ListOptions: db.ListOptions{
153+
ListAll: true,
154+
},
146155
Keyword: "hello",
147156
RepoIDs: []int64{1, 4},
148157
},
@@ -161,6 +170,9 @@ var cases = []*testIndexerCase{
161170
{ID: 1007, Title: "hello world", RepoID: 5, IsPublic: false},
162171
},
163172
SearchOptions: &internal.SearchOptions{
173+
ListOptions: db.ListOptions{
174+
ListAll: true,
175+
},
164176
Keyword: "hello",
165177
RepoIDs: []int64{1, 4},
166178
AllPublic: true,
@@ -242,6 +254,9 @@ var cases = []*testIndexerCase{
242254
{ID: 1004, Title: "hello e", LabelIDs: []int64{}},
243255
},
244256
SearchOptions: &internal.SearchOptions{
257+
ListOptions: db.ListOptions{
258+
ListAll: true,
259+
},
245260
Keyword: "hello",
246261
IncludedLabelIDs: []int64{2000, 2001},
247262
ExcludedLabelIDs: []int64{2003},
@@ -259,6 +274,9 @@ var cases = []*testIndexerCase{
259274
{ID: 1004, Title: "hello e", LabelIDs: []int64{}},
260275
},
261276
SearchOptions: &internal.SearchOptions{
277+
ListOptions: db.ListOptions{
278+
ListAll: true,
279+
},
262280
Keyword: "hello",
263281
IncludedAnyLabelIDs: []int64{2001, 2002},
264282
ExcludedLabelIDs: []int64{2003},

0 commit comments

Comments
 (0)