@@ -10,7 +10,7 @@ import (
10
10
"code.gitea.io/gitea/models/db"
11
11
repo_model "code.gitea.io/gitea/models/repo"
12
12
"code.gitea.io/gitea/models/unittest"
13
- "code.gitea.io/gitea/modules/util "
13
+ "code.gitea.io/gitea/modules/optional "
14
14
15
15
"github.com/stretchr/testify/assert"
16
16
)
@@ -27,62 +27,62 @@ func getTestCases() []struct {
27
27
}{
28
28
{
29
29
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 ) },
31
31
count : 7 ,
32
32
},
33
33
{
34
34
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 ) },
36
36
count : 14 ,
37
37
},
38
38
{
39
39
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 ) },
41
41
count : 14 ,
42
42
},
43
43
{
44
44
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 ) },
46
46
count : 14 ,
47
47
},
48
48
{
49
49
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 ) },
51
51
count : 14 ,
52
52
},
53
53
{
54
54
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 ) },
56
56
count : 14 ,
57
57
},
58
58
{
59
59
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 ) },
61
61
count : 2 ,
62
62
},
63
63
{
64
64
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 ) },
66
66
count : 0 ,
67
67
},
68
68
{
69
69
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 ) },
71
71
count : 2 ,
72
72
},
73
73
{
74
74
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 ) },
76
76
count : 4 ,
77
77
},
78
78
{
79
79
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 ) },
81
81
count : 0 ,
82
82
},
83
83
{
84
84
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 ) },
86
86
count : 4 ,
87
87
},
88
88
{
@@ -117,32 +117,32 @@ func getTestCases() []struct {
117
117
},
118
118
{
119
119
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 ) },
121
121
count : 1 ,
122
122
},
123
123
{
124
124
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 ) },
126
126
count : 2 ,
127
127
},
128
128
{
129
129
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 ) },
131
131
count : 7 ,
132
132
},
133
133
{
134
134
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 ) },
136
136
count : 14 ,
137
137
},
138
138
{
139
139
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 ) },
141
141
count : 33 ,
142
142
},
143
143
{
144
144
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 ) },
146
146
count : 38 ,
147
147
},
148
148
{
@@ -157,12 +157,12 @@ func getTestCases() []struct {
157
157
},
158
158
{
159
159
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 ) },
161
161
count : 33 ,
162
162
},
163
163
{
164
164
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 ) },
166
166
count : 2 ,
167
167
},
168
168
{
@@ -190,7 +190,7 @@ func TestSearchRepository(t *testing.T) {
190
190
PageSize : 10 ,
191
191
},
192
192
Keyword : "repo_12" ,
193
- Collaborate : util . OptionalBoolFalse ,
193
+ Collaborate : optional . Some ( false ) ,
194
194
})
195
195
196
196
assert .NoError (t , err )
@@ -205,7 +205,7 @@ func TestSearchRepository(t *testing.T) {
205
205
PageSize : 10 ,
206
206
},
207
207
Keyword : "test_repo" ,
208
- Collaborate : util . OptionalBoolFalse ,
208
+ Collaborate : optional . Some ( false ) ,
209
209
})
210
210
211
211
assert .NoError (t , err )
@@ -220,7 +220,7 @@ func TestSearchRepository(t *testing.T) {
220
220
},
221
221
Keyword : "repo_13" ,
222
222
Private : true ,
223
- Collaborate : util . OptionalBoolFalse ,
223
+ Collaborate : optional . Some ( false ) ,
224
224
})
225
225
226
226
assert .NoError (t , err )
@@ -236,7 +236,7 @@ func TestSearchRepository(t *testing.T) {
236
236
},
237
237
Keyword : "test_repo" ,
238
238
Private : true ,
239
- Collaborate : util . OptionalBoolFalse ,
239
+ Collaborate : optional . Some ( false ) ,
240
240
})
241
241
242
242
assert .NoError (t , err )
@@ -257,7 +257,7 @@ func TestSearchRepository(t *testing.T) {
257
257
PageSize : 10 ,
258
258
},
259
259
Keyword : "description_14" ,
260
- Collaborate : util . OptionalBoolFalse ,
260
+ Collaborate : optional . Some ( false ) ,
261
261
IncludeDescription : true ,
262
262
})
263
263
@@ -274,7 +274,7 @@ func TestSearchRepository(t *testing.T) {
274
274
PageSize : 10 ,
275
275
},
276
276
Keyword : "description_14" ,
277
- Collaborate : util . OptionalBoolFalse ,
277
+ Collaborate : optional . Some ( false ) ,
278
278
IncludeDescription : false ,
279
279
})
280
280
@@ -327,30 +327,25 @@ func TestSearchRepository(t *testing.T) {
327
327
assert .False (t , repo .IsPrivate )
328
328
}
329
329
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 )
332
332
} 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 )
338
335
}
339
336
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 )
345
339
}
346
340
}
347
341
348
342
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
+ }
354
349
}
355
350
}
356
351
}
0 commit comments