@@ -429,22 +429,33 @@ AAAjQmxvYgAAAGm7ENm9SGxMtAFVvPUsPJTF6PbtAAAAAFcVogEJAAAAAQAAAA==`)
429429
430430 t .Run ("SearchService" , func (t * testing.T ) {
431431 cases := []struct {
432- Query string
433- Skip int
434- Take int
435- ExpectedTotal int64
436- ExpectedResults int
432+ Query string
433+ Skip int
434+ Take int
435+ ExpectedTotal int64
436+ ExpectedResults int
437+ ExpectedExactMatch bool
437438 }{
438- {"" , 0 , 0 , 1 , 1 },
439- {"" , 0 , 10 , 1 , 1 },
440- {"gitea" , 0 , 10 , 0 , 0 },
441- {"test" , 0 , 10 , 1 , 1 },
442- {"test" , 1 , 10 , 1 , 0 },
439+ {"" , 0 , 0 , 4 , 4 , false },
440+ {"" , 0 , 10 , 4 , 4 , false },
441+ {"gitea" , 0 , 10 , 0 , 0 , false },
442+ {"test" , 0 , 10 , 1 , 1 , false },
443+ {"test" , 1 , 10 , 1 , 0 , false },
444+ {"almost.similar" , 0 , 0 , 3 , 3 , true },
443445 }
444446
445- req := NewRequestWithBody (t , "PUT" , url , createPackage (packageName , "1.0.99" )).
446- AddBasicAuth (user .Name )
447- MakeRequest (t , req , http .StatusCreated )
447+ fakePackages := []string {
448+ packageName ,
449+ "almost.similar.dependency" ,
450+ "almost.similar" ,
451+ "almost.similar.dependant" ,
452+ }
453+
454+ for _ , fakePackageName := range fakePackages {
455+ req := NewRequestWithBody (t , "PUT" , url , createPackage (fakePackageName , "1.0.99" )).
456+ AddBasicAuth (user .Name )
457+ MakeRequest (t , req , http .StatusCreated )
458+ }
448459
449460 t .Run ("v2" , func (t * testing.T ) {
450461 t .Run ("Search()" , func (t * testing.T ) {
@@ -491,6 +502,63 @@ AAAjQmxvYgAAAGm7ENm9SGxMtAFVvPUsPJTF6PbtAAAAAFcVogEJAAAAAQAAAA==`)
491502 }
492503 })
493504
505+ t .Run ("Packages()" , func (t * testing.T ) {
506+ defer tests .PrintCurrentTest (t )()
507+
508+ t .Run ("substringof" , func (t * testing.T ) {
509+ defer tests .PrintCurrentTest (t )()
510+
511+ for i , c := range cases {
512+ req := NewRequest (t , "GET" , fmt .Sprintf ("%s/Packages()?$filter=substringof('%s',tolower(Id))&$skip=%d&$top=%d" , url , c .Query , c .Skip , c .Take )).
513+ AddBasicAuth (user .Name )
514+ resp := MakeRequest (t , req , http .StatusOK )
515+
516+ var result FeedResponse
517+ decodeXML (t , resp , & result )
518+
519+ assert .Equal (t , c .ExpectedTotal , result .Count , "case %d: unexpected total hits" , i )
520+ assert .Len (t , result .Entries , c .ExpectedResults , "case %d: unexpected result count" , i )
521+
522+ req = NewRequest (t , "GET" , fmt .Sprintf ("%s/Packages()/$count?$filter=substringof('%s',tolower(Id))&$skip=%d&$top=%d" , url , c .Query , c .Skip , c .Take )).
523+ AddBasicAuth (user .Name )
524+ resp = MakeRequest (t , req , http .StatusOK )
525+
526+ assert .Equal (t , strconv .FormatInt (c .ExpectedTotal , 10 ), resp .Body .String (), "case %d: unexpected total hits" , i )
527+ }
528+ })
529+
530+ t .Run ("IdEq" , func (t * testing.T ) {
531+ defer tests .PrintCurrentTest (t )()
532+
533+ for i , c := range cases {
534+ if c .Query == "" {
535+ // Ignore the `tolower(Id) eq ''` as it's unlikely to happen
536+ continue
537+ }
538+ req := NewRequest (t , "GET" , fmt .Sprintf ("%s/Packages()?$filter=(tolower(Id) eq '%s')&$skip=%d&$top=%d" , url , c .Query , c .Skip , c .Take )).
539+ AddBasicAuth (user .Name )
540+ resp := MakeRequest (t , req , http .StatusOK )
541+
542+ var result FeedResponse
543+ decodeXML (t , resp , & result )
544+
545+ expectedCount := 0
546+ if c .ExpectedExactMatch {
547+ expectedCount = 1
548+ }
549+
550+ assert .Equal (t , int64 (expectedCount ), result .Count , "case %d: unexpected total hits" , i )
551+ assert .Len (t , result .Entries , expectedCount , "case %d: unexpected result count" , i )
552+
553+ req = NewRequest (t , "GET" , fmt .Sprintf ("%s/Packages()/$count?$filter=(tolower(Id) eq '%s')&$skip=%d&$top=%d" , url , c .Query , c .Skip , c .Take )).
554+ AddBasicAuth (user .Name )
555+ resp = MakeRequest (t , req , http .StatusOK )
556+
557+ assert .Equal (t , strconv .FormatInt (int64 (expectedCount ), 10 ), resp .Body .String (), "case %d: unexpected total hits" , i )
558+ }
559+ })
560+ })
561+
494562 t .Run ("Next" , func (t * testing.T ) {
495563 req := NewRequest (t , "GET" , fmt .Sprintf ("%s/Search()?searchTerm='test'&$skip=0&$top=1" , url )).
496564 AddBasicAuth (user .Name )
@@ -548,9 +616,11 @@ AAAjQmxvYgAAAGm7ENm9SGxMtAFVvPUsPJTF6PbtAAAAAFcVogEJAAAAAQAAAA==`)
548616 })
549617 })
550618
551- req = NewRequest (t , "DELETE" , fmt .Sprintf ("%s/%s/%s" , url , packageName , "1.0.99" )).
552- AddBasicAuth (user .Name )
553- MakeRequest (t , req , http .StatusNoContent )
619+ for _ , fakePackageName := range fakePackages {
620+ req := NewRequest (t , "DELETE" , fmt .Sprintf ("%s/%s/%s" , url , fakePackageName , "1.0.99" )).
621+ AddBasicAuth (user .Name )
622+ MakeRequest (t , req , http .StatusNoContent )
623+ }
554624 })
555625
556626 t .Run ("RegistrationService" , func (t * testing.T ) {
0 commit comments