tests/integration: simplify code (#37249)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: wxiaoguang <2114189+wxiaoguang@users.noreply.github.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Claude (Opus 4.7) <noreply@anthropic.com>
This commit is contained in:
@@ -5,7 +5,6 @@ package integration
|
||||
|
||||
import (
|
||||
"archive/tar"
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"fmt"
|
||||
@@ -16,6 +15,7 @@ import (
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
cran_module "code.gitea.io/gitea/modules/packages/cran"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
"code.gitea.io/gitea/tests"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -144,15 +144,6 @@ func TestPackageCran(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Binary", func(t *testing.T) {
|
||||
createArchive := func(filename string, content []byte) *bytes.Buffer {
|
||||
var buf bytes.Buffer
|
||||
archive := zip.NewWriter(&buf)
|
||||
w, _ := archive.Create(filename)
|
||||
w.Write(content)
|
||||
archive.Close()
|
||||
return &buf
|
||||
}
|
||||
|
||||
t.Run("Upload", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
@@ -161,24 +152,21 @@ func TestPackageCran(t *testing.T) {
|
||||
req := NewRequestWithBody(t, "PUT", uploadURL, bytes.NewReader([]byte{}))
|
||||
MakeRequest(t, req, http.StatusUnauthorized)
|
||||
|
||||
req = NewRequestWithBody(t, "PUT", uploadURL, createArchive(
|
||||
"dummy.txt",
|
||||
[]byte{},
|
||||
)).AddBasicAuth(user.Name)
|
||||
req = NewRequestWithBody(t, "PUT", uploadURL, test.WriteZipArchive(map[string]string{
|
||||
"dummy.txt": "",
|
||||
})).AddBasicAuth(user.Name)
|
||||
MakeRequest(t, req, http.StatusBadRequest)
|
||||
|
||||
req = NewRequestWithBody(t, "PUT", uploadURL+"?platform=&rversion=", createArchive(
|
||||
"package/DESCRIPTION",
|
||||
createDescription(packageName, packageVersion),
|
||||
)).AddBasicAuth(user.Name)
|
||||
req = NewRequestWithBody(t, "PUT", uploadURL+"?platform=&rversion=", test.WriteZipArchive(map[string]string{
|
||||
"package/DESCRIPTION": string(createDescription(packageName, packageVersion)),
|
||||
})).AddBasicAuth(user.Name)
|
||||
MakeRequest(t, req, http.StatusBadRequest)
|
||||
|
||||
uploadURL += "?platform=windows&rversion=4.2"
|
||||
|
||||
req = NewRequestWithBody(t, "PUT", uploadURL, createArchive(
|
||||
"package/DESCRIPTION",
|
||||
createDescription(packageName, packageVersion),
|
||||
)).AddBasicAuth(user.Name)
|
||||
req = NewRequestWithBody(t, "PUT", uploadURL, test.WriteZipArchive(map[string]string{
|
||||
"package/DESCRIPTION": string(createDescription(packageName, packageVersion)),
|
||||
})).AddBasicAuth(user.Name)
|
||||
MakeRequest(t, req, http.StatusCreated)
|
||||
|
||||
pvs, err := packages.GetVersionsByPackageType(t.Context(), user.ID, packages.TypeCran)
|
||||
@@ -189,10 +177,9 @@ func TestPackageCran(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, pfs, 2)
|
||||
|
||||
req = NewRequestWithBody(t, "PUT", uploadURL, createArchive(
|
||||
"package/DESCRIPTION",
|
||||
createDescription(packageName, packageVersion),
|
||||
)).AddBasicAuth(user.Name)
|
||||
req = NewRequestWithBody(t, "PUT", uploadURL, test.WriteZipArchive(map[string]string{
|
||||
"package/DESCRIPTION": string(createDescription(packageName, packageVersion)),
|
||||
})).AddBasicAuth(user.Name)
|
||||
MakeRequest(t, req, http.StatusConflict)
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user