@@ -10,6 +10,7 @@ import (
10
10
"encoding/base64"
11
11
"fmt"
12
12
"io"
13
+ "io/ioutil"
13
14
"net/http"
14
15
"testing"
15
16
@@ -43,23 +44,29 @@ func TestPackageNuGet(t *testing.T) {
43
44
symbolFilename := "test.pdb"
44
45
symbolID := "d910bb6948bd4c6cb40155bcf52c3c94"
45
46
46
- var buf bytes.Buffer
47
- archive := zip .NewWriter (& buf )
48
- w , _ := archive .Create ("package.nuspec" )
49
- w .Write ([]byte (`<?xml version="1.0" encoding="utf-8"?>
50
- <package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
51
- <metadata>
52
- <id>` + packageName + `</id>
53
- <version>` + packageVersion + `</version>
54
- <authors>` + packageAuthors + `</authors>
55
- <description>` + packageDescription + `</description>
56
- <group targetFramework=".NETStandard2.0">
57
- <dependency id="Microsoft.CSharp" version="4.5.0" />
58
- </group>
59
- </metadata>
60
- </package>` ))
61
- archive .Close ()
62
- content := buf .Bytes ()
47
+ createPackage := func (id , version string ) io.Reader {
48
+ var buf bytes.Buffer
49
+ archive := zip .NewWriter (& buf )
50
+ w , _ := archive .Create ("package.nuspec" )
51
+ w .Write ([]byte (`<?xml version="1.0" encoding="utf-8"?>
52
+ <package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
53
+ <metadata>
54
+ <id>` + id + `</id>
55
+ <version>` + version + `</version>
56
+ <authors>` + packageAuthors + `</authors>
57
+ <description>` + packageDescription + `</description>
58
+ <dependencies>
59
+ <group targetFramework=".NETStandard2.0">
60
+ <dependency id="Microsoft.CSharp" version="4.5.0" />
61
+ </group>
62
+ </dependencies>
63
+ </metadata>
64
+ </package>` ))
65
+ archive .Close ()
66
+ return & buf
67
+ }
68
+
69
+ content , _ := ioutil .ReadAll (createPackage (packageName , packageVersion ))
63
70
64
71
url := fmt .Sprintf ("/api/packages/%s/nuget" , user .Name )
65
72
@@ -159,7 +166,7 @@ func TestPackageNuGet(t *testing.T) {
159
166
t .Run ("SymbolPackage" , func (t * testing.T ) {
160
167
defer PrintCurrentTest (t )()
161
168
162
- createPackage := func (id , packageType string ) io.Reader {
169
+ createSymbolPackage := func (id , packageType string ) io.Reader {
163
170
var buf bytes.Buffer
164
171
archive := zip .NewWriter (& buf )
165
172
@@ -185,15 +192,15 @@ AAAjQmxvYgAAAGm7ENm9SGxMtAFVvPUsPJTF6PbtAAAAAFcVogEJAAAAAQAAAA==`)
185
192
return & buf
186
193
}
187
194
188
- req := NewRequestWithBody (t , "PUT" , fmt .Sprintf ("%s/symbolpackage" , url ), createPackage ("unknown-package" , "SymbolsPackage" ))
195
+ req := NewRequestWithBody (t , "PUT" , fmt .Sprintf ("%s/symbolpackage" , url ), createSymbolPackage ("unknown-package" , "SymbolsPackage" ))
189
196
req = AddBasicAuthHeader (req , user .Name )
190
197
MakeRequest (t , req , http .StatusNotFound )
191
198
192
- req = NewRequestWithBody (t , "PUT" , fmt .Sprintf ("%s/symbolpackage" , url ), createPackage (packageName , "DummyPackage" ))
199
+ req = NewRequestWithBody (t , "PUT" , fmt .Sprintf ("%s/symbolpackage" , url ), createSymbolPackage (packageName , "DummyPackage" ))
193
200
req = AddBasicAuthHeader (req , user .Name )
194
201
MakeRequest (t , req , http .StatusBadRequest )
195
202
196
- req = NewRequestWithBody (t , "PUT" , fmt .Sprintf ("%s/symbolpackage" , url ), createPackage (packageName , "SymbolsPackage" ))
203
+ req = NewRequestWithBody (t , "PUT" , fmt .Sprintf ("%s/symbolpackage" , url ), createSymbolPackage (packageName , "SymbolsPackage" ))
197
204
req = AddBasicAuthHeader (req , user .Name )
198
205
MakeRequest (t , req , http .StatusCreated )
199
206
@@ -237,7 +244,7 @@ AAAjQmxvYgAAAGm7ENm9SGxMtAFVvPUsPJTF6PbtAAAAAFcVogEJAAAAAQAAAA==`)
237
244
}
238
245
}
239
246
240
- req = NewRequestWithBody (t , "PUT" , fmt .Sprintf ("%s/symbolpackage" , url ), createPackage (packageName , "SymbolsPackage" ))
247
+ req = NewRequestWithBody (t , "PUT" , fmt .Sprintf ("%s/symbolpackage" , url ), createSymbolPackage (packageName , "SymbolsPackage" ))
241
248
req = AddBasicAuthHeader (req , user .Name )
242
249
MakeRequest (t , req , http .StatusConflict )
243
250
})
@@ -315,6 +322,43 @@ AAAjQmxvYgAAAGm7ENm9SGxMtAFVvPUsPJTF6PbtAAAAAFcVogEJAAAAAQAAAA==`)
315
322
assert .Equal (t , c .ExpectedTotal , result .TotalHits , "case %d: unexpected total hits" , i )
316
323
assert .Len (t , result .Data , c .ExpectedResults , "case %d: unexpected result count" , i )
317
324
}
325
+
326
+ t .Run ("EnforceGrouped" , func (t * testing.T ) {
327
+ defer PrintCurrentTest (t )()
328
+
329
+ req := NewRequestWithBody (t , "PUT" , url , createPackage (packageName + ".dummy" , "1.0.0" ))
330
+ req = AddBasicAuthHeader (req , user .Name )
331
+ MakeRequest (t , req , http .StatusCreated )
332
+
333
+ req = NewRequestWithBody (t , "PUT" , url , createPackage (packageName , "1.0.99" ))
334
+ req = AddBasicAuthHeader (req , user .Name )
335
+ MakeRequest (t , req , http .StatusCreated )
336
+
337
+ req = NewRequest (t , "GET" , fmt .Sprintf ("%s/query?q=%s" , url , packageName ))
338
+ req = AddBasicAuthHeader (req , user .Name )
339
+ resp := MakeRequest (t , req , http .StatusOK )
340
+
341
+ var result nuget.SearchResultResponse
342
+ DecodeJSON (t , resp , & result )
343
+
344
+ assert .EqualValues (t , 3 , result .TotalHits )
345
+ assert .Len (t , result .Data , 2 )
346
+ for _ , sr := range result .Data {
347
+ if sr .ID == packageName {
348
+ assert .Len (t , sr .Versions , 2 )
349
+ } else {
350
+ assert .Len (t , sr .Versions , 1 )
351
+ }
352
+ }
353
+
354
+ req = NewRequest (t , "DELETE" , fmt .Sprintf ("%s/%s/%s" , url , packageName + ".dummy" , "1.0.0" ))
355
+ req = AddBasicAuthHeader (req , user .Name )
356
+ MakeRequest (t , req , http .StatusNoContent )
357
+
358
+ req = NewRequest (t , "DELETE" , fmt .Sprintf ("%s/%s/%s" , url , packageName , "1.0.99" ))
359
+ req = AddBasicAuthHeader (req , user .Name )
360
+ MakeRequest (t , req , http .StatusNoContent )
361
+ })
318
362
})
319
363
320
364
t .Run ("RegistrationService" , func (t * testing.T ) {
0 commit comments