@@ -10,7 +10,7 @@ import (
1010 "code.gitea.io/gitea/models/db"
1111 repo_model "code.gitea.io/gitea/models/repo"
1212 "code.gitea.io/gitea/models/unittest"
13- "code.gitea.io/gitea/modules/util "
13+ "code.gitea.io/gitea/modules/optional "
1414
1515 "github.com/stretchr/testify/assert"
1616)
@@ -27,62 +27,62 @@ func getTestCases() []struct {
2727 }{
2828 {
2929 name : "PublicRepositoriesByName" ,
30- opts : & repo_model.SearchRepoOptions {Keyword : "big_test_" , ListOptions : db.ListOptions {PageSize : 10 }, Collaborate : util . OptionalBoolFalse },
30+ opts : & repo_model.SearchRepoOptions {Keyword : "big_test_" , ListOptions : db.ListOptions {PageSize : 10 }, Collaborate : optional . Some ( false ) },
3131 count : 7 ,
3232 },
3333 {
3434 name : "PublicAndPrivateRepositoriesByName" ,
35- opts : & repo_model.SearchRepoOptions {Keyword : "big_test_" , ListOptions : db.ListOptions {Page : 1 , PageSize : 10 }, Private : true , Collaborate : util . OptionalBoolFalse },
35+ opts : & repo_model.SearchRepoOptions {Keyword : "big_test_" , ListOptions : db.ListOptions {Page : 1 , PageSize : 10 }, Private : true , Collaborate : optional . Some ( false ) },
3636 count : 14 ,
3737 },
3838 {
3939 name : "PublicAndPrivateRepositoriesByNameWithPagesizeLimitFirstPage" ,
40- opts : & repo_model.SearchRepoOptions {Keyword : "big_test_" , ListOptions : db.ListOptions {Page : 1 , PageSize : 5 }, Private : true , Collaborate : util . OptionalBoolFalse },
40+ opts : & repo_model.SearchRepoOptions {Keyword : "big_test_" , ListOptions : db.ListOptions {Page : 1 , PageSize : 5 }, Private : true , Collaborate : optional . Some ( false ) },
4141 count : 14 ,
4242 },
4343 {
4444 name : "PublicAndPrivateRepositoriesByNameWithPagesizeLimitSecondPage" ,
45- opts : & repo_model.SearchRepoOptions {Keyword : "big_test_" , ListOptions : db.ListOptions {Page : 2 , PageSize : 5 }, Private : true , Collaborate : util . OptionalBoolFalse },
45+ opts : & repo_model.SearchRepoOptions {Keyword : "big_test_" , ListOptions : db.ListOptions {Page : 2 , PageSize : 5 }, Private : true , Collaborate : optional . Some ( false ) },
4646 count : 14 ,
4747 },
4848 {
4949 name : "PublicAndPrivateRepositoriesByNameWithPagesizeLimitThirdPage" ,
50- opts : & repo_model.SearchRepoOptions {Keyword : "big_test_" , ListOptions : db.ListOptions {Page : 3 , PageSize : 5 }, Private : true , Collaborate : util . OptionalBoolFalse },
50+ opts : & repo_model.SearchRepoOptions {Keyword : "big_test_" , ListOptions : db.ListOptions {Page : 3 , PageSize : 5 }, Private : true , Collaborate : optional . Some ( false ) },
5151 count : 14 ,
5252 },
5353 {
5454 name : "PublicAndPrivateRepositoriesByNameWithPagesizeLimitFourthPage" ,
55- opts : & repo_model.SearchRepoOptions {Keyword : "big_test_" , ListOptions : db.ListOptions {Page : 3 , PageSize : 5 }, Private : true , Collaborate : util . OptionalBoolFalse },
55+ opts : & repo_model.SearchRepoOptions {Keyword : "big_test_" , ListOptions : db.ListOptions {Page : 3 , PageSize : 5 }, Private : true , Collaborate : optional . Some ( false ) },
5656 count : 14 ,
5757 },
5858 {
5959 name : "PublicRepositoriesOfUser" ,
60- opts : & repo_model.SearchRepoOptions {ListOptions : db.ListOptions {Page : 1 , PageSize : 10 }, OwnerID : 15 , Collaborate : util . OptionalBoolFalse },
60+ opts : & repo_model.SearchRepoOptions {ListOptions : db.ListOptions {Page : 1 , PageSize : 10 }, OwnerID : 15 , Collaborate : optional . Some ( false ) },
6161 count : 2 ,
6262 },
6363 {
6464 name : "PublicRepositoriesOfUser2" ,
65- opts : & repo_model.SearchRepoOptions {ListOptions : db.ListOptions {Page : 1 , PageSize : 10 }, OwnerID : 18 , Collaborate : util . OptionalBoolFalse },
65+ opts : & repo_model.SearchRepoOptions {ListOptions : db.ListOptions {Page : 1 , PageSize : 10 }, OwnerID : 18 , Collaborate : optional . Some ( false ) },
6666 count : 0 ,
6767 },
6868 {
6969 name : "PublicRepositoriesOfOrg3" ,
70- opts : & repo_model.SearchRepoOptions {ListOptions : db.ListOptions {Page : 1 , PageSize : 10 }, OwnerID : 20 , Collaborate : util . OptionalBoolFalse },
70+ opts : & repo_model.SearchRepoOptions {ListOptions : db.ListOptions {Page : 1 , PageSize : 10 }, OwnerID : 20 , Collaborate : optional . Some ( false ) },
7171 count : 2 ,
7272 },
7373 {
7474 name : "PublicAndPrivateRepositoriesOfUser" ,
75- opts : & repo_model.SearchRepoOptions {ListOptions : db.ListOptions {Page : 1 , PageSize : 10 }, OwnerID : 15 , Private : true , Collaborate : util . OptionalBoolFalse },
75+ opts : & repo_model.SearchRepoOptions {ListOptions : db.ListOptions {Page : 1 , PageSize : 10 }, OwnerID : 15 , Private : true , Collaborate : optional . Some ( false ) },
7676 count : 4 ,
7777 },
7878 {
7979 name : "PublicAndPrivateRepositoriesOfUser2" ,
80- opts : & repo_model.SearchRepoOptions {ListOptions : db.ListOptions {Page : 1 , PageSize : 10 }, OwnerID : 18 , Private : true , Collaborate : util . OptionalBoolFalse },
80+ opts : & repo_model.SearchRepoOptions {ListOptions : db.ListOptions {Page : 1 , PageSize : 10 }, OwnerID : 18 , Private : true , Collaborate : optional . Some ( false ) },
8181 count : 0 ,
8282 },
8383 {
8484 name : "PublicAndPrivateRepositoriesOfOrg3" ,
85- opts : & repo_model.SearchRepoOptions {ListOptions : db.ListOptions {Page : 1 , PageSize : 10 }, OwnerID : 20 , Private : true , Collaborate : util . OptionalBoolFalse },
85+ opts : & repo_model.SearchRepoOptions {ListOptions : db.ListOptions {Page : 1 , PageSize : 10 }, OwnerID : 20 , Private : true , Collaborate : optional . Some ( false ) },
8686 count : 4 ,
8787 },
8888 {
@@ -117,32 +117,32 @@ func getTestCases() []struct {
117117 },
118118 {
119119 name : "PublicRepositoriesOfOrganization" ,
120- opts : & repo_model.SearchRepoOptions {ListOptions : db.ListOptions {Page : 1 , PageSize : 10 }, OwnerID : 17 , Collaborate : util . OptionalBoolFalse },
120+ opts : & repo_model.SearchRepoOptions {ListOptions : db.ListOptions {Page : 1 , PageSize : 10 }, OwnerID : 17 , Collaborate : optional . Some ( false ) },
121121 count : 1 ,
122122 },
123123 {
124124 name : "PublicAndPrivateRepositoriesOfOrganization" ,
125- opts : & repo_model.SearchRepoOptions {ListOptions : db.ListOptions {Page : 1 , PageSize : 10 }, OwnerID : 17 , Private : true , Collaborate : util . OptionalBoolFalse },
125+ opts : & repo_model.SearchRepoOptions {ListOptions : db.ListOptions {Page : 1 , PageSize : 10 }, OwnerID : 17 , Private : true , Collaborate : optional . Some ( false ) },
126126 count : 2 ,
127127 },
128128 {
129129 name : "AllPublic/PublicRepositoriesByName" ,
130- opts : & repo_model.SearchRepoOptions {Keyword : "big_test_" , ListOptions : db.ListOptions {PageSize : 10 }, AllPublic : true , Collaborate : util . OptionalBoolFalse },
130+ opts : & repo_model.SearchRepoOptions {Keyword : "big_test_" , ListOptions : db.ListOptions {PageSize : 10 }, AllPublic : true , Collaborate : optional . Some ( false ) },
131131 count : 7 ,
132132 },
133133 {
134134 name : "AllPublic/PublicAndPrivateRepositoriesByName" ,
135- opts : & repo_model.SearchRepoOptions {Keyword : "big_test_" , ListOptions : db.ListOptions {Page : 1 , PageSize : 10 }, Private : true , AllPublic : true , Collaborate : util . OptionalBoolFalse },
135+ opts : & repo_model.SearchRepoOptions {Keyword : "big_test_" , ListOptions : db.ListOptions {Page : 1 , PageSize : 10 }, Private : true , AllPublic : true , Collaborate : optional . Some ( false ) },
136136 count : 14 ,
137137 },
138138 {
139139 name : "AllPublic/PublicRepositoriesOfUserIncludingCollaborative" ,
140- opts : & repo_model.SearchRepoOptions {ListOptions : db.ListOptions {Page : 1 , PageSize : 10 }, OwnerID : 15 , AllPublic : true , Template : util . OptionalBoolFalse },
140+ opts : & repo_model.SearchRepoOptions {ListOptions : db.ListOptions {Page : 1 , PageSize : 10 }, OwnerID : 15 , AllPublic : true , Template : optional . Some ( false ) },
141141 count : 33 ,
142142 },
143143 {
144144 name : "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborative" ,
145- opts : & repo_model.SearchRepoOptions {ListOptions : db.ListOptions {Page : 1 , PageSize : 10 }, OwnerID : 15 , Private : true , AllPublic : true , AllLimited : true , Template : util . OptionalBoolFalse },
145+ opts : & repo_model.SearchRepoOptions {ListOptions : db.ListOptions {Page : 1 , PageSize : 10 }, OwnerID : 15 , Private : true , AllPublic : true , AllLimited : true , Template : optional . Some ( false ) },
146146 count : 38 ,
147147 },
148148 {
@@ -157,12 +157,12 @@ func getTestCases() []struct {
157157 },
158158 {
159159 name : "AllPublic/PublicRepositoriesOfOrganization" ,
160- opts : & repo_model.SearchRepoOptions {ListOptions : db.ListOptions {Page : 1 , PageSize : 10 }, OwnerID : 17 , AllPublic : true , Collaborate : util . OptionalBoolFalse , Template : util . OptionalBoolFalse },
160+ opts : & repo_model.SearchRepoOptions {ListOptions : db.ListOptions {Page : 1 , PageSize : 10 }, OwnerID : 17 , AllPublic : true , Collaborate : optional . Some ( false ) , Template : optional . Some ( false ) },
161161 count : 33 ,
162162 },
163163 {
164164 name : "AllTemplates" ,
165- opts : & repo_model.SearchRepoOptions {ListOptions : db.ListOptions {Page : 1 , PageSize : 10 }, Template : util . OptionalBoolTrue },
165+ opts : & repo_model.SearchRepoOptions {ListOptions : db.ListOptions {Page : 1 , PageSize : 10 }, Template : optional . Some ( true ) },
166166 count : 2 ,
167167 },
168168 {
@@ -190,7 +190,7 @@ func TestSearchRepository(t *testing.T) {
190190 PageSize : 10 ,
191191 },
192192 Keyword : "repo_12" ,
193- Collaborate : util . OptionalBoolFalse ,
193+ Collaborate : optional . Some ( false ) ,
194194 })
195195
196196 assert .NoError (t , err )
@@ -205,7 +205,7 @@ func TestSearchRepository(t *testing.T) {
205205 PageSize : 10 ,
206206 },
207207 Keyword : "test_repo" ,
208- Collaborate : util . OptionalBoolFalse ,
208+ Collaborate : optional . Some ( false ) ,
209209 })
210210
211211 assert .NoError (t , err )
@@ -220,7 +220,7 @@ func TestSearchRepository(t *testing.T) {
220220 },
221221 Keyword : "repo_13" ,
222222 Private : true ,
223- Collaborate : util . OptionalBoolFalse ,
223+ Collaborate : optional . Some ( false ) ,
224224 })
225225
226226 assert .NoError (t , err )
@@ -236,7 +236,7 @@ func TestSearchRepository(t *testing.T) {
236236 },
237237 Keyword : "test_repo" ,
238238 Private : true ,
239- Collaborate : util . OptionalBoolFalse ,
239+ Collaborate : optional . Some ( false ) ,
240240 })
241241
242242 assert .NoError (t , err )
@@ -257,7 +257,7 @@ func TestSearchRepository(t *testing.T) {
257257 PageSize : 10 ,
258258 },
259259 Keyword : "description_14" ,
260- Collaborate : util . OptionalBoolFalse ,
260+ Collaborate : optional . Some ( false ) ,
261261 IncludeDescription : true ,
262262 })
263263
@@ -274,7 +274,7 @@ func TestSearchRepository(t *testing.T) {
274274 PageSize : 10 ,
275275 },
276276 Keyword : "description_14" ,
277- Collaborate : util . OptionalBoolFalse ,
277+ Collaborate : optional . Some ( false ) ,
278278 IncludeDescription : false ,
279279 })
280280
@@ -327,30 +327,25 @@ func TestSearchRepository(t *testing.T) {
327327 assert .False (t , repo .IsPrivate )
328328 }
329329
330- if testCase .opts .Fork == util . OptionalBoolTrue && testCase .opts .Mirror == util . OptionalBoolTrue {
331- assert .True (t , repo .IsFork || repo .IsMirror )
330+ if testCase .opts .Fork . Value () && testCase .opts .Mirror . Value () {
331+ assert .True (t , repo .IsFork && repo .IsMirror )
332332 } else {
333- switch testCase .opts .Fork {
334- case util .OptionalBoolFalse :
335- assert .False (t , repo .IsFork )
336- case util .OptionalBoolTrue :
337- assert .True (t , repo .IsFork )
333+ if testCase .opts .Fork .Has () {
334+ assert .Equal (t , testCase .opts .Fork .Value (), repo .IsFork )
338335 }
339336
340- switch testCase .opts .Mirror {
341- case util .OptionalBoolFalse :
342- assert .False (t , repo .IsMirror )
343- case util .OptionalBoolTrue :
344- assert .True (t , repo .IsMirror )
337+ if testCase .opts .Mirror .Has () {
338+ assert .Equal (t , testCase .opts .Mirror .Value (), repo .IsMirror )
345339 }
346340 }
347341
348342 if testCase .opts .OwnerID > 0 && ! testCase .opts .AllPublic {
349- switch testCase .opts .Collaborate {
350- case util .OptionalBoolFalse :
351- assert .Equal (t , testCase .opts .OwnerID , repo .Owner .ID )
352- case util .OptionalBoolTrue :
353- assert .NotEqual (t , testCase .opts .OwnerID , repo .Owner .ID )
343+ if testCase .opts .Collaborate .Has () {
344+ if testCase .opts .Collaborate .Value () {
345+ assert .NotEqual (t , testCase .opts .OwnerID , repo .Owner .ID )
346+ } else {
347+ assert .Equal (t , testCase .opts .OwnerID , repo .Owner .ID )
348+ }
354349 }
355350 }
356351 }
0 commit comments