diff options
Diffstat (limited to 'tests/integration/api_packages_arch_test.go')
-rw-r--r-- | tests/integration/api_packages_arch_test.go | 94 |
1 files changed, 64 insertions, 30 deletions
diff --git a/tests/integration/api_packages_arch_test.go b/tests/integration/api_packages_arch_test.go index 9c7a9dd19d..e5778b4203 100644 --- a/tests/integration/api_packages_arch_test.go +++ b/tests/integration/api_packages_arch_test.go @@ -79,6 +79,34 @@ license = MIT`) return buf.Bytes() } + readIndexContent := func(r io.Reader) (map[string]string, error) { + gzr, err := gzip.NewReader(r) + if err != nil { + return nil, err + } + + content := make(map[string]string) + + tr := tar.NewReader(gzr) + for { + hd, err := tr.Next() + if err == io.EOF { + break + } + if err != nil { + return nil, err + } + + buf, err := io.ReadAll(tr) + if err != nil { + return nil, err + } + + content[hd.Name] = string(buf) + } + + return content, nil + } compressions := []string{"gz", "xz", "zst"} repositories := []string{"main", "testing", "with/slash", ""} @@ -135,7 +163,7 @@ license = MIT`) assert.Condition(t, func() bool { seen := false expectedFilename := fmt.Sprintf("%s-%s-aarch64.pkg.tar.%s", packageName, packageVersion, compression) - expectedCompositeKey := fmt.Sprintf("%s|aarch64", repository) + expectedCompositeKey := repository + "|aarch64" for _, pf := range pfs { if pf.Name == expectedFilename && pf.CompositeKey == expectedCompositeKey { if seen { @@ -171,35 +199,6 @@ license = MIT`) MakeRequest(t, req, http.StatusConflict) }) - readIndexContent := func(r io.Reader) (map[string]string, error) { - gzr, err := gzip.NewReader(r) - if err != nil { - return nil, err - } - - content := make(map[string]string) - - tr := tar.NewReader(gzr) - for { - hd, err := tr.Next() - if err == io.EOF { - break - } - if err != nil { - return nil, err - } - - buf, err := io.ReadAll(tr) - if err != nil { - return nil, err - } - - content[hd.Name] = string(buf) - } - - return content, nil - } - t.Run("Index", func(t *testing.T) { defer tests.PrintCurrentTest(t)() @@ -299,4 +298,39 @@ license = MIT`) }) } } + t.Run("KeepLastVersion", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + pkgVer1 := createPackage("gz", "gitea-test", "1.0.0", "aarch64") + pkgVer2 := createPackage("gz", "gitea-test", "1.0.1", "aarch64") + req := NewRequestWithBody(t, "PUT", rootURL, bytes.NewReader(pkgVer1)). + AddBasicAuth(user.Name) + MakeRequest(t, req, http.StatusCreated) + req = NewRequestWithBody(t, "PUT", rootURL, bytes.NewReader(pkgVer2)). + AddBasicAuth(user.Name) + MakeRequest(t, req, http.StatusCreated) + + req = NewRequest(t, "GET", fmt.Sprintf("%s/aarch64/%s", rootURL, arch_service.IndexArchiveFilename)) + resp := MakeRequest(t, req, http.StatusOK) + + content, err := readIndexContent(resp.Body) + assert.NoError(t, err) + assert.Len(t, content, 2) + + _, has := content["gitea-test-1.0.0/desc"] + assert.False(t, has) + _, has = content["gitea-test-1.0.1/desc"] + assert.True(t, has) + + req = NewRequest(t, "DELETE", rootURL+"/gitea-test/1.0.1/aarch64"). + AddBasicAuth(user.Name) + MakeRequest(t, req, http.StatusNoContent) + + req = NewRequest(t, "GET", fmt.Sprintf("%s/aarch64/%s", rootURL, arch_service.IndexArchiveFilename)) + resp = MakeRequest(t, req, http.StatusOK) + content, err = readIndexContent(resp.Body) + assert.NoError(t, err) + assert.Len(t, content, 2) + _, has = content["gitea-test-1.0.0/desc"] + assert.True(t, has) + }) } |