5
5
package models
6
6
7
7
import (
8
+ "strings"
8
9
"testing"
9
10
10
11
"code.gitea.io/gitea/models/db"
@@ -261,6 +262,16 @@ func TestSearchRepository(t *testing.T) {
261
262
opts : & SearchRepoOptions {ListOptions : db.ListOptions {Page : 1 , PageSize : 10 }, Template : util .OptionalBoolTrue },
262
263
count : 2 ,
263
264
},
265
+ {
266
+ name : "OwnerSlashRepoSearch" ,
267
+ opts : & SearchRepoOptions {Keyword : "user/repo2" , ListOptions : db.ListOptions {Page : 1 , PageSize : 10 }, Private : true , OwnerID : 0 },
268
+ count : 3 ,
269
+ },
270
+ {
271
+ name : "OwnerSlashSearch" ,
272
+ opts : & SearchRepoOptions {Keyword : "user20/" , ListOptions : db.ListOptions {Page : 1 , PageSize : 10 }, Private : true , OwnerID : 0 },
273
+ count : 4 ,
274
+ },
264
275
}
265
276
266
277
for _ , testCase := range testCases {
@@ -285,7 +296,21 @@ func TestSearchRepository(t *testing.T) {
285
296
assert .NotEmpty (t , repo .Name )
286
297
287
298
if len (testCase .opts .Keyword ) > 0 {
288
- assert .Contains (t , repo .Name , testCase .opts .Keyword )
299
+ // Keyword match condition is different for search terms of form "owner/repo"
300
+ if strings .Count (testCase .opts .Keyword , "/" ) == 1 {
301
+ // May still match as a whole...
302
+ wholeMatch := strings .Contains (repo .Name , testCase .opts .Keyword )
303
+
304
+ pieces := strings .Split (testCase .opts .Keyword , "/" )
305
+ ownerName := pieces [0 ]
306
+ repoName := pieces [1 ]
307
+ // ... or match in parts
308
+ splitMatch := strings .Contains (repo .OwnerName , ownerName ) && strings .Contains (repo .Name , repoName )
309
+
310
+ assert .True (t , wholeMatch || splitMatch , "Keyword '%s' does not match repo '%s/%s'" , testCase .opts .Keyword , repo .Owner .Name , repo .Name )
311
+ } else {
312
+ assert .Contains (t , repo .Name , testCase .opts .Keyword )
313
+ }
289
314
}
290
315
291
316
if ! testCase .opts .Private {
0 commit comments