@@ -23,6 +23,7 @@ import (
23
23
"code.gitea.io/gitea/models/unittest"
24
24
user_model "code.gitea.io/gitea/models/user"
25
25
arch_model "code.gitea.io/gitea/modules/packages/arch"
26
+ "code.gitea.io/gitea/modules/test"
26
27
"code.gitea.io/gitea/modules/util"
27
28
"code.gitea.io/gitea/tests"
28
29
@@ -40,6 +41,9 @@ func TestPackageArchNew(t *testing.T) {
40
41
}
41
42
rootURL := fmt .Sprintf ("/api/packages/%s/arch" , user .Name )
42
43
44
+ // DIFF:RepositoryKey
45
+ keyURL := fmt .Sprintf ("/api/packages/%s/arch/key" , user .Name )
46
+
43
47
pkgs := map [string ][]byte {
44
48
// pkgname = test, arch = any
45
49
"any" : unpack (`
@@ -128,14 +132,16 @@ HMhNSS1IzUsBcpJAPFAwwUXSM0u4BjoaR8EoGAWjgGQAAILFeyQADAAA
128
132
t .Run ("RepositoryKey" , func (t * testing.T ) {
129
133
defer tests .PrintCurrentTest (t )()
130
134
131
- req := NewRequest (t , "GET" , rootURL + "/repository.key" )
135
+ req := NewRequest (t , "GET" , keyURL )
132
136
resp := MakeRequest (t , req , http .StatusOK )
133
137
134
138
require .Equal (t , "application/pgp-keys" , resp .Header ().Get ("Content-Type" ))
135
139
require .Contains (t , resp .Body .String (), "-----BEGIN PGP PUBLIC KEY BLOCK-----" )
136
140
})
137
141
138
- for _ , group := range []string {"" , "arch" , "arch/os" , "x86_64" } {
142
+ // DIFF:RepositoryName
143
+ //for _, group := range []string{"arch", "arch/os"} {
144
+ for _ , group := range []string {"main-repo" , "test-repo" } {
139
145
groupURL := rootURL + util .Iif (group == "" , "" , "/" + group )
140
146
t .Run (fmt .Sprintf ("Upload[%s]" , group ), func (t * testing.T ) {
141
147
defer tests .PrintCurrentTest (t )()
@@ -149,7 +155,9 @@ HMhNSS1IzUsBcpJAPFAwwUXSM0u4BjoaR8EoGAWjgGQAAILFeyQADAAA
149
155
150
156
req = NewRequestWithBody (t , "PUT" , groupURL , bytes .NewBuffer ([]byte ("any string" ))).
151
157
AddBasicAuth (user .Name )
152
- MakeRequest (t , req , http .StatusBadRequest )
158
+ // DIFF:InvalidPackage
159
+ //MakeRequest(t, req, http.StatusBadRequest)
160
+ MakeRequest (t , req , http .StatusInternalServerError )
153
161
154
162
pvs , err := packages .GetVersionsByPackageType (db .DefaultContext , user .ID , packages .TypeArch )
155
163
require .NoError (t , err )
@@ -166,11 +174,13 @@ HMhNSS1IzUsBcpJAPFAwwUXSM0u4BjoaR8EoGAWjgGQAAILFeyQADAAA
166
174
require .NoError (t , err )
167
175
size := 0
168
176
for _ , pf := range pfs {
169
- if pf .CompositeKey == group {
177
+ if strings . HasPrefix ( pf .CompositeKey , group + "|" ) {
170
178
size ++
171
179
}
172
180
}
173
- require .Equal (t , 2 , size ) // zst and zst.sig
181
+ // DIFF:PackageFileStore
182
+ //require.Equal(t, 2, size) // zst and zst.sig
183
+ require .Equal (t , 1 , size ) // zst
174
184
175
185
pb , err := packages .GetBlobByID (db .DefaultContext , pfs [0 ].BlobID )
176
186
require .NoError (t , err )
@@ -192,28 +202,30 @@ HMhNSS1IzUsBcpJAPFAwwUXSM0u4BjoaR8EoGAWjgGQAAILFeyQADAAA
192
202
193
203
t .Run (fmt .Sprintf ("Download[%s]" , group ), func (t * testing.T ) {
194
204
defer tests .PrintCurrentTest (t )()
195
- req := NewRequest (t , "GET" , groupURL + "/x86_64/test-1.0.0-1-x86_64.pkg.tar.zst" )
205
+
206
+ // DIFF:PackageFileNameExt
207
+ req := NewRequest (t , "GET" , groupURL + "/x86_64/test-1.0.0-1-x86_64.pck.tar.zst" )
196
208
resp := MakeRequest (t , req , http .StatusOK )
197
209
require .Equal (t , pkgs ["x86_64" ], resp .Body .Bytes ())
198
210
199
- req = NewRequest (t , "GET" , groupURL + "/x86_64/test-1.0.0-1-any.pkg .tar.zst" )
211
+ req = NewRequest (t , "GET" , groupURL + "/x86_64/test-1.0.0-1-any.pck .tar.zst" )
200
212
resp = MakeRequest (t , req , http .StatusOK )
201
213
require .Equal (t , pkgs ["any" ], resp .Body .Bytes ())
202
214
203
215
// get other group
204
- req = NewRequest (t , "GET" , rootURL + "/unknown/x86_64/test-1.0.0-1-aarch64.pkg .tar.zst" )
216
+ req = NewRequest (t , "GET" , rootURL + "/unknown/x86_64/test-1.0.0-1-aarch64.pck .tar.zst" )
205
217
MakeRequest (t , req , http .StatusNotFound )
206
218
})
207
219
208
220
t .Run (fmt .Sprintf ("SignVerify[%s]" , group ), func (t * testing.T ) {
209
221
defer tests .PrintCurrentTest (t )()
210
- req := NewRequest (t , "GET" , rootURL + "/repository.key" )
222
+ req := NewRequest (t , "GET" , keyURL )
211
223
respPub := MakeRequest (t , req , http .StatusOK )
212
224
213
- req = NewRequest (t , "GET" , groupURL + "/x86_64/test-1.0.0-1-any.pkg .tar.zst" )
225
+ req = NewRequest (t , "GET" , groupURL + "/x86_64/test-1.0.0-1-any.pck .tar.zst" )
214
226
respPkg := MakeRequest (t , req , http .StatusOK )
215
227
216
- req = NewRequest (t , "GET" , groupURL + "/x86_64/test-1.0.0-1-any.pkg .tar.zst.sig" )
228
+ req = NewRequest (t , "GET" , groupURL + "/x86_64/test-1.0.0-1-any.pck .tar.zst.sig" )
217
229
respSig := MakeRequest (t , req , http .StatusOK )
218
230
219
231
if err := gpgVerify (respPub .Body .Bytes (), respSig .Body .Bytes (), respPkg .Body .Bytes ()); err != nil {
@@ -223,7 +235,7 @@ HMhNSS1IzUsBcpJAPFAwwUXSM0u4BjoaR8EoGAWjgGQAAILFeyQADAAA
223
235
224
236
t .Run (fmt .Sprintf ("RepositoryDB[%s]" , group ), func (t * testing.T ) {
225
237
defer tests .PrintCurrentTest (t )()
226
- req := NewRequest (t , "GET" , rootURL + "/repository.key" )
238
+ req := NewRequest (t , "GET" , keyURL )
227
239
respPub := MakeRequest (t , req , http .StatusOK )
228
240
229
241
req = NewRequest (t , "GET" , groupURL + "/x86_64/base.db" )
@@ -237,8 +249,14 @@ HMhNSS1IzUsBcpJAPFAwwUXSM0u4BjoaR8EoGAWjgGQAAILFeyQADAAA
237
249
}
238
250
files , err := listTarGzFiles (respPkg .Body .Bytes ())
239
251
require .NoError (t , err )
240
- require .Len (t , files , 1 )
252
+
253
+ // DIFF:RepositoryDBFiles
254
+ //require.Len(t, files, 1)
255
+ require .Len (t , files , 2 ) // files, desc
241
256
for s , d := range files {
257
+ if ! strings .HasSuffix (s , "/desc" ) {
258
+ continue
259
+ }
242
260
name := getProperty (string (d .Data ), "NAME" )
243
261
ver := getProperty (string (d .Data ), "VERSION" )
244
262
require .Equal (t , name + "-" + ver + "/desc" , s )
@@ -255,48 +273,51 @@ HMhNSS1IzUsBcpJAPFAwwUXSM0u4BjoaR8EoGAWjgGQAAILFeyQADAAA
255
273
t .Run (fmt .Sprintf ("Delete[%s]" , group ), func (t * testing.T ) {
256
274
defer tests .PrintCurrentTest (t )()
257
275
// test data
258
- req := NewRequestWithBody (t , "PUT" , groupURL , bytes .NewReader (pkgs ["otherXZ " ])).
276
+ req := NewRequestWithBody (t , "PUT" , groupURL , bytes .NewReader (pkgs ["otherZST " ])).
259
277
AddBasicAuth (user .Name )
260
278
MakeRequest (t , req , http .StatusCreated )
261
279
280
+ //DIFF:DeletePackageURL
281
+ //req = NewRequestWithBody(t, "DELETE", rootURL+"/base/notfound/1.0.0-1/any", nil).
262
282
req = NewRequestWithBody (t , "DELETE" , rootURL + "/base/notfound/1.0.0-1/any" , nil ).
263
283
AddBasicAuth (user .Name )
264
284
MakeRequest (t , req , http .StatusNotFound )
265
285
266
- req = NewRequestWithBody (t , "DELETE" , groupURL + "/test/1.0.0-1/x86_64" , nil ).
286
+ //req = NewRequestWithBody(t, "DELETE", groupURL+"/test/1.0.0-1/x86_64", nil).
287
+ req = NewRequestWithBody (t , "DELETE" , groupURL + "/x86_64/test-1.0.0-1-x86_64.pck.tar.zst" , nil ).
267
288
AddBasicAuth (user .Name )
268
289
MakeRequest (t , req , http .StatusNoContent )
269
290
270
- req = NewRequestWithBody (t , "DELETE" , groupURL + "/test/1.0.0-1/any" , nil ).
291
+ //req = NewRequestWithBody(t, "DELETE", groupURL+"/test/1.0.0-1/any", nil).
292
+ req = NewRequestWithBody (t , "DELETE" , groupURL + "/any/test-1.0.0-1-any.pck.tar.zst" , nil ).
271
293
AddBasicAuth (user .Name )
272
294
MakeRequest (t , req , http .StatusNoContent )
273
295
274
296
req = NewRequest (t , "GET" , groupURL + "/x86_64/base.db" )
275
297
respPkg := MakeRequest (t , req , http .StatusOK )
276
298
files , err := listTarGzFiles (respPkg .Body .Bytes ())
277
299
require .NoError (t , err )
278
- require .Len (t , files , 1 )
300
+ require .Len (t , files , 2 ) // now, only "test2-1.0.0-1/files" and "test2-1.0.0-1/desc"
279
301
280
- req = NewRequestWithBody (t , "DELETE" , groupURL + "/test2/1.0.0-1/any" , nil ).
281
- AddBasicAuth (user .Name )
302
+ // req = NewRequestWithBody(t, "DELETE", groupURL+"/test2/1.0.0-1/any", nil).
303
+ req = NewRequestWithBody ( t , "DELETE" , groupURL + "/any/test2-1.0.0-1-any.pck.tar.zst" , nil ). AddBasicAuth (user .Name )
282
304
MakeRequest (t , req , http .StatusNoContent )
283
305
284
- req = NewRequest (t , "GET" , groupURL + "/x86_64/base.db" ).
285
- AddBasicAuth (user .Name )
306
+ req = NewRequest (t , "GET" , groupURL + "/x86_64/base.db" ).AddBasicAuth (user .Name )
286
307
MakeRequest (t , req , http .StatusNotFound )
287
308
288
- req = NewRequestWithBody (t , "DELETE" , groupURL + "/test/1.0.0-1/aarch64" , nil ).
289
- AddBasicAuth (user .Name )
309
+ // req = NewRequestWithBody(t, "DELETE", groupURL+"/test/1.0.0-1/aarch64", nil).
310
+ req = NewRequestWithBody ( t , "DELETE" , groupURL + "/aarch64/test-1.0.0-1-aarch64.pck.tar.zst" , nil ). AddBasicAuth (user .Name )
290
311
MakeRequest (t , req , http .StatusNoContent )
291
312
292
- req = NewRequest (t , "GET" , groupURL + "/aarch64/base.db" ).
293
- AddBasicAuth (user .Name )
313
+ req = NewRequest (t , "GET" , groupURL + "/aarch64/base.db" ).AddBasicAuth (user .Name )
294
314
MakeRequest (t , req , http .StatusNotFound )
295
315
})
296
316
317
+ // DIFF:OtherPackageType
297
318
for tp , key := range map [string ]string {
298
- "GZ" : "otherGZ" ,
299
- "XZ" : "otherXZ" ,
319
+ // "GZ": "otherGZ",
320
+ // "XZ": "otherXZ",
300
321
"ZST" : "otherZST" ,
301
322
} {
302
323
t .Run (fmt .Sprintf ("Upload%s[%s]" , tp , group ), func (t * testing.T ) {
@@ -305,12 +326,12 @@ HMhNSS1IzUsBcpJAPFAwwUXSM0u4BjoaR8EoGAWjgGQAAILFeyQADAAA
305
326
AddBasicAuth (user .Name )
306
327
MakeRequest (t , req , http .StatusCreated )
307
328
308
- req = NewRequest (t , "GET" , groupURL + "/x86_64/test2-1.0.0-1-any.pkg .tar." + strings .ToLower (tp ))
329
+ req = NewRequest (t , "GET" , groupURL + "/x86_64/test2-1.0.0-1-any.pck .tar." + strings .ToLower (tp ))
309
330
resp := MakeRequest (t , req , http .StatusOK )
310
331
require .Equal (t , pkgs [key ], resp .Body .Bytes ())
311
332
312
- req = NewRequestWithBody (t , "DELETE" , groupURL + "/test2/1.0.0-1/any" , nil ).
313
- AddBasicAuth (user .Name )
333
+ // req = NewRequestWithBody(t, "DELETE", groupURL+"/test2/1.0.0-1/any", nil).AddBasicAuth(user.Name)
334
+ req = NewRequestWithBody ( t , "DELETE" , groupURL + "/any/test2-1.0.0-1-any.pck.tar." + strings . ToLower ( tp ), nil ). AddBasicAuth (user .Name )
314
335
MakeRequest (t , req , http .StatusNoContent )
315
336
})
316
337
}
@@ -326,21 +347,22 @@ HMhNSS1IzUsBcpJAPFAwwUXSM0u4BjoaR8EoGAWjgGQAAILFeyQADAAA
326
347
wg .Add (1 )
327
348
go func (i string ) {
328
349
defer wg .Done ()
329
- req := NewRequestWithBody (t , "PUT" , rootURL , bytes .NewReader (pkgs [i ])).
350
+ req := NewRequestWithBody (t , "PUT" , rootURL + "/concur-repo" , bytes .NewReader (pkgs [i ])).
330
351
AddBasicAuth (user .Name )
331
352
MakeRequest (t , req , http .StatusCreated )
332
353
}(tag )
333
354
}
334
355
wg .Wait ()
335
356
for _ , target := range targets {
336
- req := NewRequestWithBody (t , "DELETE" , rootURL + "/test/1.0.0-1/" + target , nil ).
337
- AddBasicAuth (user .Name )
357
+ req := NewRequestWithBody (t , "DELETE" , rootURL + "/concur-repo/" + target + "/test-1.0.0-1-" + target + ".pck.tar.zst" , nil ).AddBasicAuth (user .Name )
338
358
MakeRequest (t , req , http .StatusNoContent )
339
359
}
340
360
})
341
361
342
362
t .Run ("List Meta.Arch[any]" , func (t * testing.T ) {
343
363
defer tests .PrintCurrentTest (t )()
364
+ // DIFF:RepositoryName
365
+ defer test .MockVariableValue (& rootURL , rootURL + "/list-repo" )()
344
366
345
367
req := NewRequestWithBody (t , "PUT" , rootURL , bytes .NewReader (pkgs ["any" ])).AddBasicAuth (user .Name )
346
368
MakeRequest (t , req , http .StatusCreated )
@@ -350,17 +372,19 @@ HMhNSS1IzUsBcpJAPFAwwUXSM0u4BjoaR8EoGAWjgGQAAILFeyQADAAA
350
372
351
373
files , err := listTarGzFiles (respPkg .Body .Bytes ())
352
374
require .NoError (t , err )
353
- require .Len (t , files , 1 ) // only one package: "test"
375
+ //require.Len(t, files, 1)
376
+ require .Len (t , files , 2 ) // only one package: "test (files, desc)"
354
377
355
- req = NewRequestWithBody (t , "PUT" , rootURL , bytes .NewReader (pkgs ["otherXZ " ])).AddBasicAuth (user .Name )
378
+ req = NewRequestWithBody (t , "PUT" , rootURL , bytes .NewReader (pkgs ["otherZST " ])).AddBasicAuth (user .Name )
356
379
MakeRequest (t , req , http .StatusCreated )
357
380
358
381
req = NewRequest (t , "GET" , rootURL + "/x86_64/base.db" )
359
382
resp := MakeRequest (t , req , http .StatusOK )
360
383
361
384
files , err = listTarGzFiles (resp .Body .Bytes ())
362
385
require .NoError (t , err )
363
- require .Len (t , files , 2 ) // now there are 2 packages: "test" and "test2"
386
+ //require.Len(t, files, 2) // now there are 2 packages: "test" and "test2"
387
+ require .Len (t , files , 4 ) // now there are 2 packages: "test" and "test2" (files, desc)*2
364
388
})
365
389
}
366
390
0 commit comments