@@ -31,6 +31,7 @@ func TestPackageDebian(t *testing.T) {
3131
3232 packageName := "gitea"
3333 packageVersion := "1.0.3"
34+ packageVersion2 := "1.0.4"
3435 packageDescription := "Package Description"
3536
3637 createArchive := func (name , version , architecture string ) io.Reader {
@@ -80,11 +81,11 @@ func TestPackageDebian(t *testing.T) {
8081 for _ , component := range components {
8182 for _ , architecture := range architectures {
8283 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+
8386 t .Run ("Upload" , func (t * testing.T ) {
8487 defer tests .PrintCurrentTest (t )()
8588
86- uploadURL := fmt .Sprintf ("%s/pool/%s/%s/upload" , rootURL , distribution , component )
87-
8889 req := NewRequestWithBody (t , "PUT" , uploadURL , bytes .NewReader ([]byte {}))
8990 MakeRequest (t , req , http .StatusUnauthorized )
9091
@@ -100,18 +101,17 @@ func TestPackageDebian(t *testing.T) {
100101 AddBasicAuthHeader (req , user .Name )
101102 MakeRequest (t , req , http .StatusCreated )
102103
103- pvs , err := packages .GetVersionsByPackageType (db .DefaultContext , user .ID , packages .TypeDebian )
104+ pv , err := packages .GetVersionByNameAndVersion (db .DefaultContext , user .ID , packages .TypeDebian , packageName , packageVersion )
104105 assert .NoError (t , err )
105- assert .Len (t , pvs , 1 )
106106
107- pd , err := packages .GetPackageDescriptor (db .DefaultContext , pvs [ 0 ] )
107+ pd , err := packages .GetPackageDescriptor (db .DefaultContext , pv )
108108 assert .NoError (t , err )
109109 assert .Nil (t , pd .SemVer )
110110 assert .IsType (t , & debian_module.Metadata {}, pd .Metadata )
111111 assert .Equal (t , packageName , pd .Package .Name )
112112 assert .Equal (t , packageVersion , pd .Version .Version )
113113
114- pfs , err := packages .GetFilesByVersionID (db .DefaultContext , pvs [ 0 ] .ID )
114+ pfs , err := packages .GetFilesByVersionID (db .DefaultContext , pv .ID )
115115 assert .NoError (t , err )
116116 assert .NotEmpty (t , pfs )
117117 assert .Condition (t , func () bool {
@@ -162,17 +162,23 @@ func TestPackageDebian(t *testing.T) {
162162 t .Run ("Packages" , func (t * testing.T ) {
163163 defer tests .PrintCurrentTest (t )()
164164
165+ req := NewRequestWithBody (t , "PUT" , uploadURL , createArchive (packageName , packageVersion2 , architecture ))
166+ AddBasicAuthHeader (req , user .Name )
167+ MakeRequest (t , req , http .StatusCreated )
168+
165169 url := fmt .Sprintf ("%s/dists/%s/%s/binary-%s/Packages" , rootURL , distribution , component , architecture )
166170
167- req : = NewRequest (t , "GET" , url )
171+ req = NewRequest (t , "GET" , url )
168172 resp := MakeRequest (t , req , http .StatusOK )
169173
170174 body := resp .Body .String ()
171175
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 ))
176182
177183 req = NewRequest (t , "GET" , url + ".gz" )
178184 MakeRequest (t , req , http .StatusOK )
@@ -198,14 +204,14 @@ func TestPackageDebian(t *testing.T) {
198204
199205 body := resp .Body .String ()
200206
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 " )
203209
204210 for _ , component := range components {
205211 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 ))
209215 }
210216 }
211217
@@ -241,6 +247,10 @@ func TestPackageDebian(t *testing.T) {
241247 AddBasicAuthHeader (req , user .Name )
242248 MakeRequest (t , req , http .StatusNoContent )
243249
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+
244254 req = NewRequest (t , "GET" , fmt .Sprintf ("%s/dists/%s/%s/binary-%s/Packages" , rootURL , distribution , component , architecture ))
245255 MakeRequest (t , req , http .StatusNotFound )
246256 }
@@ -250,7 +260,7 @@ func TestPackageDebian(t *testing.T) {
250260
251261 body := resp .Body .String ()
252262
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 " )
255265 })
256266}
0 commit comments