@@ -31,6 +31,7 @@ func TestPackageDebian(t *testing.T) {
31
31
32
32
packageName := "gitea"
33
33
packageVersion := "1.0.3"
34
+ packageVersion2 := "1.0.4"
34
35
packageDescription := "Package Description"
35
36
36
37
createArchive := func (name , version , architecture string ) io.Reader {
@@ -80,11 +81,11 @@ func TestPackageDebian(t *testing.T) {
80
81
for _ , component := range components {
81
82
for _ , architecture := range architectures {
82
83
t .Run (fmt .Sprintf ("[Component:%s,Architecture:%s]" , component , architecture ), func (t * testing.T ) {
84
+ uploadURL := fmt .Sprintf ("%s/pool/%s/%s/upload" , rootURL , distribution , component )
85
+
83
86
t .Run ("Upload" , func (t * testing.T ) {
84
87
defer tests .PrintCurrentTest (t )()
85
88
86
- uploadURL := fmt .Sprintf ("%s/pool/%s/%s/upload" , rootURL , distribution , component )
87
-
88
89
req := NewRequestWithBody (t , "PUT" , uploadURL , bytes .NewReader ([]byte {}))
89
90
MakeRequest (t , req , http .StatusUnauthorized )
90
91
@@ -100,18 +101,17 @@ func TestPackageDebian(t *testing.T) {
100
101
AddBasicAuthHeader (req , user .Name )
101
102
MakeRequest (t , req , http .StatusCreated )
102
103
103
- pvs , err := packages .GetVersionsByPackageType (db .DefaultContext , user .ID , packages .TypeDebian )
104
+ pv , err := packages .GetVersionByNameAndVersion (db .DefaultContext , user .ID , packages .TypeDebian , packageName , packageVersion )
104
105
assert .NoError (t , err )
105
- assert .Len (t , pvs , 1 )
106
106
107
- pd , err := packages .GetPackageDescriptor (db .DefaultContext , pvs [ 0 ] )
107
+ pd , err := packages .GetPackageDescriptor (db .DefaultContext , pv )
108
108
assert .NoError (t , err )
109
109
assert .Nil (t , pd .SemVer )
110
110
assert .IsType (t , & debian_module.Metadata {}, pd .Metadata )
111
111
assert .Equal (t , packageName , pd .Package .Name )
112
112
assert .Equal (t , packageVersion , pd .Version .Version )
113
113
114
- pfs , err := packages .GetFilesByVersionID (db .DefaultContext , pvs [ 0 ] .ID )
114
+ pfs , err := packages .GetFilesByVersionID (db .DefaultContext , pv .ID )
115
115
assert .NoError (t , err )
116
116
assert .NotEmpty (t , pfs )
117
117
assert .Condition (t , func () bool {
@@ -162,17 +162,23 @@ func TestPackageDebian(t *testing.T) {
162
162
t .Run ("Packages" , func (t * testing.T ) {
163
163
defer tests .PrintCurrentTest (t )()
164
164
165
+ req := NewRequestWithBody (t , "PUT" , uploadURL , createArchive (packageName , packageVersion2 , architecture ))
166
+ AddBasicAuthHeader (req , user .Name )
167
+ MakeRequest (t , req , http .StatusCreated )
168
+
165
169
url := fmt .Sprintf ("%s/dists/%s/%s/binary-%s/Packages" , rootURL , distribution , component , architecture )
166
170
167
- req : = NewRequest (t , "GET" , url )
171
+ req = NewRequest (t , "GET" , url )
168
172
resp := MakeRequest (t , req , http .StatusOK )
169
173
170
174
body := resp .Body .String ()
171
175
172
- assert .Contains (t , body , "Package: " + packageName )
173
- assert .Contains (t , body , "Version: " + packageVersion )
174
- assert .Contains (t , body , "Architecture: " + architecture )
175
- assert .Contains (t , body , fmt .Sprintf ("Filename: pool/%s/%s/%s_%s_%s.deb" , distribution , component , packageName , packageVersion , architecture ))
176
+ assert .Contains (t , body , "Package: " + packageName + "\n " )
177
+ assert .Contains (t , body , "Version: " + packageVersion + "\n " )
178
+ assert .Contains (t , body , "Version: " + packageVersion2 + "\n " )
179
+ assert .Contains (t , body , "Architecture: " + architecture + "\n " )
180
+ assert .Contains (t , body , fmt .Sprintf ("Filename: pool/%s/%s/%s_%s_%s.deb\n " , distribution , component , packageName , packageVersion , architecture ))
181
+ assert .Contains (t , body , fmt .Sprintf ("Filename: pool/%s/%s/%s_%s_%s.deb\n " , distribution , component , packageName , packageVersion2 , architecture ))
176
182
177
183
req = NewRequest (t , "GET" , url + ".gz" )
178
184
MakeRequest (t , req , http .StatusOK )
@@ -198,14 +204,14 @@ func TestPackageDebian(t *testing.T) {
198
204
199
205
body := resp .Body .String ()
200
206
201
- assert .Contains (t , body , "Components: " + strings .Join (components , " " ))
202
- assert .Contains (t , body , "Architectures: " + strings .Join (architectures , " " ))
207
+ assert .Contains (t , body , "Components: " + strings .Join (components , " " )+ " \n " )
208
+ assert .Contains (t , body , "Architectures: " + strings .Join (architectures , " " )+ " \n " )
203
209
204
210
for _ , component := range components {
205
211
for _ , architecture := range architectures {
206
- assert .Contains (t , body , fmt .Sprintf ("%s/binary-%s/Packages" , component , architecture ))
207
- assert .Contains (t , body , fmt .Sprintf ("%s/binary-%s/Packages.gz" , component , architecture ))
208
- assert .Contains (t , body , fmt .Sprintf ("%s/binary-%s/Packages.xz" , component , architecture ))
212
+ assert .Contains (t , body , fmt .Sprintf ("%s/binary-%s/Packages\n " , component , architecture ))
213
+ assert .Contains (t , body , fmt .Sprintf ("%s/binary-%s/Packages.gz\n " , component , architecture ))
214
+ assert .Contains (t , body , fmt .Sprintf ("%s/binary-%s/Packages.xz\n " , component , architecture ))
209
215
}
210
216
}
211
217
@@ -241,6 +247,10 @@ func TestPackageDebian(t *testing.T) {
241
247
AddBasicAuthHeader (req , user .Name )
242
248
MakeRequest (t , req , http .StatusNoContent )
243
249
250
+ req = NewRequest (t , "DELETE" , fmt .Sprintf ("%s/pool/%s/%s/%s/%s/%s" , rootURL , distribution , component , packageName , packageVersion2 , architecture ))
251
+ AddBasicAuthHeader (req , user .Name )
252
+ MakeRequest (t , req , http .StatusNoContent )
253
+
244
254
req = NewRequest (t , "GET" , fmt .Sprintf ("%s/dists/%s/%s/binary-%s/Packages" , rootURL , distribution , component , architecture ))
245
255
MakeRequest (t , req , http .StatusNotFound )
246
256
}
@@ -250,7 +260,7 @@ func TestPackageDebian(t *testing.T) {
250
260
251
261
body := resp .Body .String ()
252
262
253
- assert .Contains (t , body , "Components: " + strings .Join (components , " " ))
254
- assert .Contains (t , body , "Architectures: " + architectures [1 ])
263
+ assert .Contains (t , body , "Components: " + strings .Join (components , " " )+ " \n " )
264
+ assert .Contains (t , body , "Architectures: " + architectures [1 ]+ " \n " )
255
265
})
256
266
}
0 commit comments