@@ -11,6 +11,7 @@ import (
11
11
"encoding/xml"
12
12
"fmt"
13
13
"io"
14
+ "io/ioutil"
14
15
"net/http"
15
16
"net/http/httptest"
16
17
"testing"
@@ -83,25 +84,29 @@ func TestPackageNuGet(t *testing.T) {
83
84
symbolFilename := "test.pdb"
84
85
symbolID := "d910bb6948bd4c6cb40155bcf52c3c94"
85
86
86
- var buf bytes.Buffer
87
- archive := zip .NewWriter (& buf )
88
- w , _ := archive .Create ("package.nuspec" )
89
- w .Write ([]byte (`<?xml version="1.0" encoding="utf-8"?>
90
- <package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
91
- <metadata>
92
- <id>` + packageName + `</id>
93
- <version>` + packageVersion + `</version>
94
- <authors>` + packageAuthors + `</authors>
95
- <description>` + packageDescription + `</description>
96
- <dependencies>
97
- <group targetFramework=".NETStandard2.0">
98
- <dependency id="Microsoft.CSharp" version="4.5.0" />
99
- </group>
100
- </dependencies>
101
- </metadata>
102
- </package>` ))
103
- archive .Close ()
104
- content := buf .Bytes ()
87
+ createPackage := func (id , version string ) io.Reader {
88
+ var buf bytes.Buffer
89
+ archive := zip .NewWriter (& buf )
90
+ w , _ := archive .Create ("package.nuspec" )
91
+ w .Write ([]byte (`<?xml version="1.0" encoding="utf-8"?>
92
+ <package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
93
+ <metadata>
94
+ <id>` + id + `</id>
95
+ <version>` + version + `</version>
96
+ <authors>` + packageAuthors + `</authors>
97
+ <description>` + packageDescription + `</description>
98
+ <dependencies>
99
+ <group targetFramework=".NETStandard2.0">
100
+ <dependency id="Microsoft.CSharp" version="4.5.0" />
101
+ </group>
102
+ </dependencies>
103
+ </metadata>
104
+ </package>` ))
105
+ archive .Close ()
106
+ return & buf
107
+ }
108
+
109
+ content , _ := ioutil .ReadAll (createPackage (packageName , packageVersion ))
105
110
106
111
url := fmt .Sprintf ("/api/packages/%s/nuget" , user .Name )
107
112
@@ -242,7 +247,7 @@ func TestPackageNuGet(t *testing.T) {
242
247
t .Run ("SymbolPackage" , func (t * testing.T ) {
243
248
defer tests .PrintCurrentTest (t )()
244
249
245
- createPackage := func (id , packageType string ) io.Reader {
250
+ createSymbolPackage := func (id , packageType string ) io.Reader {
246
251
var buf bytes.Buffer
247
252
archive := zip .NewWriter (& buf )
248
253
@@ -268,15 +273,15 @@ AAAjQmxvYgAAAGm7ENm9SGxMtAFVvPUsPJTF6PbtAAAAAFcVogEJAAAAAQAAAA==`)
268
273
return & buf
269
274
}
270
275
271
- req := NewRequestWithBody (t , "PUT" , fmt .Sprintf ("%s/symbolpackage" , url ), createPackage ("unknown-package" , "SymbolsPackage" ))
276
+ req := NewRequestWithBody (t , "PUT" , fmt .Sprintf ("%s/symbolpackage" , url ), createSymbolPackage ("unknown-package" , "SymbolsPackage" ))
272
277
req = AddBasicAuthHeader (req , user .Name )
273
278
MakeRequest (t , req , http .StatusNotFound )
274
279
275
- req = NewRequestWithBody (t , "PUT" , fmt .Sprintf ("%s/symbolpackage" , url ), createPackage (packageName , "DummyPackage" ))
280
+ req = NewRequestWithBody (t , "PUT" , fmt .Sprintf ("%s/symbolpackage" , url ), createSymbolPackage (packageName , "DummyPackage" ))
276
281
req = AddBasicAuthHeader (req , user .Name )
277
282
MakeRequest (t , req , http .StatusBadRequest )
278
283
279
- req = NewRequestWithBody (t , "PUT" , fmt .Sprintf ("%s/symbolpackage" , url ), createPackage (packageName , "SymbolsPackage" ))
284
+ req = NewRequestWithBody (t , "PUT" , fmt .Sprintf ("%s/symbolpackage" , url ), createSymbolPackage (packageName , "SymbolsPackage" ))
280
285
req = AddBasicAuthHeader (req , user .Name )
281
286
MakeRequest (t , req , http .StatusCreated )
282
287
@@ -320,7 +325,7 @@ AAAjQmxvYgAAAGm7ENm9SGxMtAFVvPUsPJTF6PbtAAAAAFcVogEJAAAAAQAAAA==`)
320
325
}
321
326
}
322
327
323
- req = NewRequestWithBody (t , "PUT" , fmt .Sprintf ("%s/symbolpackage" , url ), createPackage (packageName , "SymbolsPackage" ))
328
+ req = NewRequestWithBody (t , "PUT" , fmt .Sprintf ("%s/symbolpackage" , url ), createSymbolPackage (packageName , "SymbolsPackage" ))
324
329
req = AddBasicAuthHeader (req , user .Name )
325
330
MakeRequest (t , req , http .StatusConflict )
326
331
})
@@ -437,6 +442,43 @@ AAAjQmxvYgAAAGm7ENm9SGxMtAFVvPUsPJTF6PbtAAAAAFcVogEJAAAAAQAAAA==`)
437
442
assert .Equal (t , c .ExpectedTotal , result .TotalHits , "case %d: unexpected total hits" , i )
438
443
assert .Len (t , result .Data , c .ExpectedResults , "case %d: unexpected result count" , i )
439
444
}
445
+
446
+ t .Run ("EnforceGrouped" , func (t * testing.T ) {
447
+ defer tests .PrintCurrentTest (t )()
448
+
449
+ req := NewRequestWithBody (t , "PUT" , url , createPackage (packageName + ".dummy" , "1.0.0" ))
450
+ req = AddBasicAuthHeader (req , user .Name )
451
+ MakeRequest (t , req , http .StatusCreated )
452
+
453
+ req = NewRequestWithBody (t , "PUT" , url , createPackage (packageName , "1.0.99" ))
454
+ req = AddBasicAuthHeader (req , user .Name )
455
+ MakeRequest (t , req , http .StatusCreated )
456
+
457
+ req = NewRequest (t , "GET" , fmt .Sprintf ("%s/query?q=%s" , url , packageName ))
458
+ req = AddBasicAuthHeader (req , user .Name )
459
+ resp := MakeRequest (t , req , http .StatusOK )
460
+
461
+ var result nuget.SearchResultResponse
462
+ DecodeJSON (t , resp , & result )
463
+
464
+ assert .EqualValues (t , 3 , result .TotalHits )
465
+ assert .Len (t , result .Data , 2 )
466
+ for _ , sr := range result .Data {
467
+ if sr .ID == packageName {
468
+ assert .Len (t , sr .Versions , 2 )
469
+ } else {
470
+ assert .Len (t , sr .Versions , 1 )
471
+ }
472
+ }
473
+
474
+ req = NewRequest (t , "DELETE" , fmt .Sprintf ("%s/%s/%s" , url , packageName + ".dummy" , "1.0.0" ))
475
+ req = AddBasicAuthHeader (req , user .Name )
476
+ MakeRequest (t , req , http .StatusNoContent )
477
+
478
+ req = NewRequest (t , "DELETE" , fmt .Sprintf ("%s/%s/%s" , url , packageName , "1.0.99" ))
479
+ req = AddBasicAuthHeader (req , user .Name )
480
+ MakeRequest (t , req , http .StatusNoContent )
481
+ })
440
482
})
441
483
})
442
484
0 commit comments