mirror of
https://github.com/go-gitea/gitea
synced 2025-12-07 13:28:25 +00:00
Merge branch 'main' into lunny/automerge_support_delete_branch
This commit is contained in:
@@ -23,8 +23,15 @@ type getUploadArtifactRequest struct {
|
||||
RetentionDays int64
|
||||
}
|
||||
|
||||
func prepareTestEnvActionsArtifacts(t *testing.T) func() {
|
||||
t.Helper()
|
||||
f := tests.PrepareTestEnv(t, 1)
|
||||
tests.PrepareArtifactsStorage(t)
|
||||
return f
|
||||
}
|
||||
|
||||
func TestActionsArtifactUploadSingleFile(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
defer prepareTestEnvActionsArtifacts(t)()
|
||||
|
||||
// acquire artifact upload url
|
||||
req := NewRequestWithJSON(t, "POST", "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts", getUploadArtifactRequest{
|
||||
@@ -38,27 +45,27 @@ func TestActionsArtifactUploadSingleFile(t *testing.T) {
|
||||
|
||||
// get upload url
|
||||
idx := strings.Index(uploadResp.FileContainerResourceURL, "/api/actions_pipeline/_apis/pipelines/")
|
||||
url := uploadResp.FileContainerResourceURL[idx:] + "?itemPath=artifact/abc.txt"
|
||||
url := uploadResp.FileContainerResourceURL[idx:] + "?itemPath=artifact/abc-2.txt"
|
||||
|
||||
// upload artifact chunk
|
||||
body := strings.Repeat("A", 1024)
|
||||
body := strings.Repeat("C", 1024)
|
||||
req = NewRequestWithBody(t, "PUT", url, strings.NewReader(body)).
|
||||
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a").
|
||||
SetHeader("Content-Range", "bytes 0-1023/1024").
|
||||
SetHeader("x-tfs-filelength", "1024").
|
||||
SetHeader("x-actions-results-md5", "1HsSe8LeLWh93ILaw1TEFQ==") // base64(md5(body))
|
||||
SetHeader("x-actions-results-md5", "XVlf820rMInUi64wmMi6EA==") // base64(md5(body))
|
||||
MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
t.Logf("Create artifact confirm")
|
||||
|
||||
// confirm artifact upload
|
||||
req = NewRequest(t, "PATCH", "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts?artifactName=artifact").
|
||||
req = NewRequest(t, "PATCH", "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts?artifactName=artifact-single").
|
||||
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
||||
MakeRequest(t, req, http.StatusOK)
|
||||
}
|
||||
|
||||
func TestActionsArtifactUploadInvalidHash(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
defer prepareTestEnvActionsArtifacts(t)()
|
||||
|
||||
// artifact id 54321 not exist
|
||||
url := "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts/8e5b948a454515dbabfc7eb718ddddddd/upload?itemPath=artifact/abc.txt"
|
||||
@@ -73,7 +80,7 @@ func TestActionsArtifactUploadInvalidHash(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestActionsArtifactConfirmUploadWithoutName(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
defer prepareTestEnvActionsArtifacts(t)()
|
||||
|
||||
req := NewRequest(t, "PATCH", "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts").
|
||||
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
||||
@@ -82,7 +89,7 @@ func TestActionsArtifactConfirmUploadWithoutName(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestActionsArtifactUploadWithoutToken(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
defer prepareTestEnvActionsArtifacts(t)()
|
||||
|
||||
req := NewRequestWithJSON(t, "POST", "/api/actions_pipeline/_apis/pipelines/workflows/1/artifacts", nil)
|
||||
MakeRequest(t, req, http.StatusUnauthorized)
|
||||
@@ -108,40 +115,51 @@ type (
|
||||
)
|
||||
|
||||
func TestActionsArtifactDownload(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
defer prepareTestEnvActionsArtifacts(t)()
|
||||
|
||||
req := NewRequest(t, "GET", "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts").
|
||||
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
var listResp listArtifactsResponse
|
||||
DecodeJSON(t, resp, &listResp)
|
||||
assert.Equal(t, int64(1), listResp.Count)
|
||||
assert.Equal(t, "artifact", listResp.Value[0].Name)
|
||||
assert.Contains(t, listResp.Value[0].FileContainerResourceURL, "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts")
|
||||
assert.Equal(t, int64(2), listResp.Count)
|
||||
|
||||
idx := strings.Index(listResp.Value[0].FileContainerResourceURL, "/api/actions_pipeline/_apis/pipelines/")
|
||||
url := listResp.Value[0].FileContainerResourceURL[idx+1:] + "?itemPath=artifact"
|
||||
// Return list might be in any order. Get one file.
|
||||
var artifactIdx int
|
||||
for i, artifact := range listResp.Value {
|
||||
if artifact.Name == "artifact-download" {
|
||||
artifactIdx = i
|
||||
break
|
||||
}
|
||||
}
|
||||
assert.NotNil(t, artifactIdx)
|
||||
assert.Equal(t, listResp.Value[artifactIdx].Name, "artifact-download")
|
||||
assert.Contains(t, listResp.Value[artifactIdx].FileContainerResourceURL, "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts")
|
||||
|
||||
idx := strings.Index(listResp.Value[artifactIdx].FileContainerResourceURL, "/api/actions_pipeline/_apis/pipelines/")
|
||||
url := listResp.Value[artifactIdx].FileContainerResourceURL[idx+1:] + "?itemPath=artifact-download"
|
||||
req = NewRequest(t, "GET", url).
|
||||
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
var downloadResp downloadArtifactResponse
|
||||
DecodeJSON(t, resp, &downloadResp)
|
||||
assert.Len(t, downloadResp.Value, 1)
|
||||
assert.Equal(t, "artifact/abc.txt", downloadResp.Value[0].Path)
|
||||
assert.Equal(t, "file", downloadResp.Value[0].ItemType)
|
||||
assert.Contains(t, downloadResp.Value[0].ContentLocation, "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts")
|
||||
assert.Equal(t, "artifact-download/abc.txt", downloadResp.Value[artifactIdx].Path)
|
||||
assert.Equal(t, "file", downloadResp.Value[artifactIdx].ItemType)
|
||||
assert.Contains(t, downloadResp.Value[artifactIdx].ContentLocation, "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts")
|
||||
|
||||
idx = strings.Index(downloadResp.Value[0].ContentLocation, "/api/actions_pipeline/_apis/pipelines/")
|
||||
url = downloadResp.Value[0].ContentLocation[idx:]
|
||||
idx = strings.Index(downloadResp.Value[artifactIdx].ContentLocation, "/api/actions_pipeline/_apis/pipelines/")
|
||||
url = downloadResp.Value[artifactIdx].ContentLocation[idx:]
|
||||
req = NewRequest(t, "GET", url).
|
||||
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
body := strings.Repeat("A", 1024)
|
||||
assert.Equal(t, resp.Body.String(), body)
|
||||
assert.Equal(t, body, resp.Body.String())
|
||||
}
|
||||
|
||||
func TestActionsArtifactUploadMultipleFile(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
defer prepareTestEnvActionsArtifacts(t)()
|
||||
|
||||
const testArtifactName = "multi-files"
|
||||
|
||||
@@ -163,14 +181,14 @@ func TestActionsArtifactUploadMultipleFile(t *testing.T) {
|
||||
|
||||
files := []uploadingFile{
|
||||
{
|
||||
Path: "abc.txt",
|
||||
Content: strings.Repeat("A", 1024),
|
||||
MD5: "1HsSe8LeLWh93ILaw1TEFQ==",
|
||||
Path: "abc-3.txt",
|
||||
Content: strings.Repeat("D", 1024),
|
||||
MD5: "9nqj7E8HZmfQtPifCJ5Zww==",
|
||||
},
|
||||
{
|
||||
Path: "xyz/def.txt",
|
||||
Content: strings.Repeat("B", 1024),
|
||||
MD5: "6fgADK/7zjadf+6cB9Q1CQ==",
|
||||
Path: "xyz/def-2.txt",
|
||||
Content: strings.Repeat("E", 1024),
|
||||
MD5: "/s1kKvxeHlUX85vaTaVxuA==",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -197,9 +215,9 @@ func TestActionsArtifactUploadMultipleFile(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestActionsArtifactDownloadMultiFiles(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
defer prepareTestEnvActionsArtifacts(t)()
|
||||
|
||||
const testArtifactName = "multi-files"
|
||||
const testArtifactName = "multi-file-download"
|
||||
|
||||
req := NewRequest(t, "GET", "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts").
|
||||
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
||||
@@ -226,7 +244,7 @@ func TestActionsArtifactDownloadMultiFiles(t *testing.T) {
|
||||
DecodeJSON(t, resp, &downloadResp)
|
||||
assert.Len(t, downloadResp.Value, 2)
|
||||
|
||||
downloads := [][]string{{"multi-files/abc.txt", "A"}, {"multi-files/xyz/def.txt", "B"}}
|
||||
downloads := [][]string{{"multi-file-download/abc.txt", "B"}, {"multi-file-download/xyz/def.txt", "C"}}
|
||||
for _, v := range downloadResp.Value {
|
||||
var bodyChar string
|
||||
var path string
|
||||
@@ -247,13 +265,12 @@ func TestActionsArtifactDownloadMultiFiles(t *testing.T) {
|
||||
req = NewRequest(t, "GET", url).
|
||||
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
body := strings.Repeat(bodyChar, 1024)
|
||||
assert.Equal(t, resp.Body.String(), body)
|
||||
assert.Equal(t, strings.Repeat(bodyChar, 1024), resp.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionsArtifactUploadWithRetentionDays(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
defer prepareTestEnvActionsArtifacts(t)()
|
||||
|
||||
// acquire artifact upload url
|
||||
req := NewRequestWithJSON(t, "POST", "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts", getUploadArtifactRequest{
|
||||
@@ -289,7 +306,7 @@ func TestActionsArtifactUploadWithRetentionDays(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestActionsArtifactOverwrite(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
defer prepareTestEnvActionsArtifacts(t)()
|
||||
|
||||
{
|
||||
// download old artifact uploaded by tests above, it should 1024 A
|
||||
@@ -300,7 +317,7 @@ func TestActionsArtifactOverwrite(t *testing.T) {
|
||||
DecodeJSON(t, resp, &listResp)
|
||||
|
||||
idx := strings.Index(listResp.Value[0].FileContainerResourceURL, "/api/actions_pipeline/_apis/pipelines/")
|
||||
url := listResp.Value[0].FileContainerResourceURL[idx+1:] + "?itemPath=artifact"
|
||||
url := listResp.Value[0].FileContainerResourceURL[idx+1:] + "?itemPath=artifact-download"
|
||||
req = NewRequest(t, "GET", url).
|
||||
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
@@ -320,14 +337,14 @@ func TestActionsArtifactOverwrite(t *testing.T) {
|
||||
// upload same artifact, it uses 4096 B
|
||||
req := NewRequestWithJSON(t, "POST", "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts", getUploadArtifactRequest{
|
||||
Type: "actions_storage",
|
||||
Name: "artifact",
|
||||
Name: "artifact-download",
|
||||
}).AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
var uploadResp uploadArtifactResponse
|
||||
DecodeJSON(t, resp, &uploadResp)
|
||||
|
||||
idx := strings.Index(uploadResp.FileContainerResourceURL, "/api/actions_pipeline/_apis/pipelines/")
|
||||
url := uploadResp.FileContainerResourceURL[idx:] + "?itemPath=artifact/abc.txt"
|
||||
url := uploadResp.FileContainerResourceURL[idx:] + "?itemPath=artifact-download/abc.txt"
|
||||
body := strings.Repeat("B", 4096)
|
||||
req = NewRequestWithBody(t, "PUT", url, strings.NewReader(body)).
|
||||
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a").
|
||||
@@ -337,7 +354,7 @@ func TestActionsArtifactOverwrite(t *testing.T) {
|
||||
MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
// confirm artifact upload
|
||||
req = NewRequest(t, "PATCH", "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts?artifactName=artifact").
|
||||
req = NewRequest(t, "PATCH", "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts?artifactName=artifact-download").
|
||||
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
||||
MakeRequest(t, req, http.StatusOK)
|
||||
}
|
||||
@@ -352,15 +369,15 @@ func TestActionsArtifactOverwrite(t *testing.T) {
|
||||
|
||||
var uploadedItem listArtifactsResponseItem
|
||||
for _, item := range listResp.Value {
|
||||
if item.Name == "artifact" {
|
||||
if item.Name == "artifact-download" {
|
||||
uploadedItem = item
|
||||
break
|
||||
}
|
||||
}
|
||||
assert.Equal(t, uploadedItem.Name, "artifact")
|
||||
assert.Equal(t, uploadedItem.Name, "artifact-download")
|
||||
|
||||
idx := strings.Index(uploadedItem.FileContainerResourceURL, "/api/actions_pipeline/_apis/pipelines/")
|
||||
url := uploadedItem.FileContainerResourceURL[idx+1:] + "?itemPath=artifact"
|
||||
url := uploadedItem.FileContainerResourceURL[idx+1:] + "?itemPath=artifact-download"
|
||||
req = NewRequest(t, "GET", url).
|
||||
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
@@ -17,7 +17,6 @@ import (
|
||||
"code.gitea.io/gitea/modules/storage"
|
||||
"code.gitea.io/gitea/routers/api/actions"
|
||||
actions_service "code.gitea.io/gitea/services/actions"
|
||||
"code.gitea.io/gitea/tests"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
@@ -34,7 +33,7 @@ func toProtoJSON(m protoreflect.ProtoMessage) io.Reader {
|
||||
}
|
||||
|
||||
func TestActionsArtifactV4UploadSingleFile(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
defer prepareTestEnvActionsArtifacts(t)()
|
||||
|
||||
token, err := actions_service.CreateAuthorizationToken(48, 792, 193)
|
||||
assert.NoError(t, err)
|
||||
@@ -81,7 +80,7 @@ func TestActionsArtifactV4UploadSingleFile(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestActionsArtifactV4UploadSingleFileWrongChecksum(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
defer prepareTestEnvActionsArtifacts(t)()
|
||||
|
||||
token, err := actions_service.CreateAuthorizationToken(48, 792, 193)
|
||||
assert.NoError(t, err)
|
||||
@@ -125,7 +124,7 @@ func TestActionsArtifactV4UploadSingleFileWrongChecksum(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestActionsArtifactV4UploadSingleFileWithRetentionDays(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
defer prepareTestEnvActionsArtifacts(t)()
|
||||
|
||||
token, err := actions_service.CreateAuthorizationToken(48, 792, 193)
|
||||
assert.NoError(t, err)
|
||||
@@ -173,7 +172,7 @@ func TestActionsArtifactV4UploadSingleFileWithRetentionDays(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestActionsArtifactV4UploadSingleFileWithPotentialHarmfulBlockID(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
defer prepareTestEnvActionsArtifacts(t)()
|
||||
|
||||
token, err := actions_service.CreateAuthorizationToken(48, 792, 193)
|
||||
assert.NoError(t, err)
|
||||
@@ -236,7 +235,7 @@ func TestActionsArtifactV4UploadSingleFileWithPotentialHarmfulBlockID(t *testing
|
||||
}
|
||||
|
||||
func TestActionsArtifactV4UploadSingleFileWithChunksOutOfOrder(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
defer prepareTestEnvActionsArtifacts(t)()
|
||||
|
||||
token, err := actions_service.CreateAuthorizationToken(48, 792, 193)
|
||||
assert.NoError(t, err)
|
||||
@@ -301,14 +300,14 @@ func TestActionsArtifactV4UploadSingleFileWithChunksOutOfOrder(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestActionsArtifactV4DownloadSingle(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
defer prepareTestEnvActionsArtifacts(t)()
|
||||
|
||||
token, err := actions_service.CreateAuthorizationToken(48, 792, 193)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// acquire artifact upload url
|
||||
req := NewRequestWithBody(t, "POST", "/twirp/github.actions.results.api.v1.ArtifactService/ListArtifacts", toProtoJSON(&actions.ListArtifactsRequest{
|
||||
NameFilter: wrapperspb.String("artifact"),
|
||||
NameFilter: wrapperspb.String("artifact-v4-download"),
|
||||
WorkflowRunBackendId: "792",
|
||||
WorkflowJobRunBackendId: "193",
|
||||
})).AddTokenAuth(token)
|
||||
@@ -319,7 +318,7 @@ func TestActionsArtifactV4DownloadSingle(t *testing.T) {
|
||||
|
||||
// confirm artifact upload
|
||||
req = NewRequestWithBody(t, "POST", "/twirp/github.actions.results.api.v1.ArtifactService/GetSignedArtifactURL", toProtoJSON(&actions.GetSignedArtifactURLRequest{
|
||||
Name: "artifact",
|
||||
Name: "artifact-v4-download",
|
||||
WorkflowRunBackendId: "792",
|
||||
WorkflowJobRunBackendId: "193",
|
||||
})).
|
||||
@@ -331,19 +330,19 @@ func TestActionsArtifactV4DownloadSingle(t *testing.T) {
|
||||
|
||||
req = NewRequest(t, "GET", finalizeResp.SignedUrl)
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
body := strings.Repeat("A", 1024)
|
||||
assert.Equal(t, resp.Body.String(), body)
|
||||
body := strings.Repeat("D", 1024)
|
||||
assert.Equal(t, body, resp.Body.String())
|
||||
}
|
||||
|
||||
func TestActionsArtifactV4Delete(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
defer prepareTestEnvActionsArtifacts(t)()
|
||||
|
||||
token, err := actions_service.CreateAuthorizationToken(48, 792, 193)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// delete artifact by name
|
||||
req := NewRequestWithBody(t, "POST", "/twirp/github.actions.results.api.v1.ArtifactService/DeleteArtifact", toProtoJSON(&actions.DeleteArtifactRequest{
|
||||
Name: "artifact",
|
||||
Name: "artifact-v4-download",
|
||||
WorkflowRunBackendId: "792",
|
||||
WorkflowJobRunBackendId: "193",
|
||||
})).AddTokenAuth(token)
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -19,6 +20,7 @@ import (
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
debian_module "code.gitea.io/gitea/modules/packages/debian"
|
||||
packages_cleanup_service "code.gitea.io/gitea/services/packages/cleanup"
|
||||
"code.gitea.io/gitea/tests"
|
||||
|
||||
"github.com/blakesmith/ar"
|
||||
@@ -263,4 +265,37 @@ func TestPackageDebian(t *testing.T) {
|
||||
assert.Contains(t, body, "Components: "+strings.Join(components, " ")+"\n")
|
||||
assert.Contains(t, body, "Architectures: "+architectures[1]+"\n")
|
||||
})
|
||||
|
||||
t.Run("Cleanup", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
rule := &packages.PackageCleanupRule{
|
||||
Enabled: true,
|
||||
RemovePattern: `.*`,
|
||||
MatchFullName: true,
|
||||
OwnerID: user.ID,
|
||||
Type: packages.TypeDebian,
|
||||
}
|
||||
|
||||
_, err := packages.InsertCleanupRule(db.DefaultContext, rule)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// When there were a lot of packages (> 50 or 100) and the code used "Iterate" to get all packages, it ever caused bugs,
|
||||
// because "Iterate" keeps a dangling SQL session but the callback function still uses the same session to execute statements.
|
||||
// The "Iterate" problem has been checked by TestContextSafety now, so here we only need to check the cleanup logic with a small number
|
||||
packagesCount := 2
|
||||
for i := 0; i < packagesCount; i++ {
|
||||
uploadURL := fmt.Sprintf("%s/pool/%s/%s/upload", rootURL, "test", "main")
|
||||
req := NewRequestWithBody(t, "PUT", uploadURL, createArchive(packageName, "1.0."+strconv.Itoa(i), "all")).AddBasicAuth(user.Name)
|
||||
MakeRequest(t, req, http.StatusCreated)
|
||||
}
|
||||
req := NewRequest(t, "GET", fmt.Sprintf("%s/dists/%s/Release", rootURL, "test"))
|
||||
MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
err = packages_cleanup_service.CleanupTask(db.DefaultContext, 0)
|
||||
assert.NoError(t, err)
|
||||
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("%s/dists/%s/Release", rootURL, "test"))
|
||||
MakeRequest(t, req, http.StatusNotFound)
|
||||
})
|
||||
}
|
||||
|
||||
+34
-18
@@ -192,20 +192,10 @@ func PrepareAttachmentsStorage(t testing.TB) {
|
||||
}))
|
||||
}
|
||||
|
||||
func PrepareTestEnv(t testing.TB, skip ...int) func() {
|
||||
t.Helper()
|
||||
ourSkip := 1
|
||||
if len(skip) > 0 {
|
||||
ourSkip += skip[0]
|
||||
}
|
||||
deferFn := PrintCurrentTest(t, ourSkip)
|
||||
|
||||
// load database fixtures
|
||||
assert.NoError(t, unittest.LoadFixtures())
|
||||
|
||||
// load git repo fixtures
|
||||
func PrepareGitRepoDirectory(t testing.TB) {
|
||||
assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
|
||||
assert.NoError(t, unittest.CopyDir(path.Join(filepath.Dir(setting.AppPath), "tests/gitea-repositories-meta"), setting.RepoRootPath))
|
||||
|
||||
ownerDirs, err := os.ReadDir(setting.RepoRootPath)
|
||||
if err != nil {
|
||||
assert.NoError(t, err, "unable to read the new repo root: %v\n", err)
|
||||
@@ -226,9 +216,25 @@ func PrepareTestEnv(t testing.TB, skip ...int) func() {
|
||||
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "pull"), 0o755)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func PrepareArtifactsStorage(t testing.TB) {
|
||||
// prepare actions artifacts directory and files
|
||||
assert.NoError(t, storage.Clean(storage.ActionsArtifacts))
|
||||
|
||||
s, err := storage.NewStorage(setting.LocalStorageType, &setting.Storage{
|
||||
Path: filepath.Join(filepath.Dir(setting.AppPath), "tests", "testdata", "data", "artifacts"),
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, s.IterateObjects("", func(p string, obj storage.Object) error {
|
||||
_, err = storage.Copy(storage.ActionsArtifacts, p, s, p)
|
||||
return err
|
||||
}))
|
||||
}
|
||||
|
||||
func PrepareLFSStorage(t testing.TB) {
|
||||
// load LFS object fixtures
|
||||
// (LFS storage can be on any of several backends, including remote servers, so we init it with the storage API)
|
||||
// (LFS storage can be on any of several backends, including remote servers, so init it with the storage API)
|
||||
lfsFixtures, err := storage.NewStorage(setting.LocalStorageType, &setting.Storage{
|
||||
Path: filepath.Join(filepath.Dir(setting.AppPath), "tests/gitea-lfs-meta"),
|
||||
})
|
||||
@@ -238,7 +244,9 @@ func PrepareTestEnv(t testing.TB, skip ...int) func() {
|
||||
_, err := storage.Copy(storage.LFS, path, lfsFixtures, path)
|
||||
return err
|
||||
}))
|
||||
}
|
||||
|
||||
func PrepareCleanPackageData(t testing.TB) {
|
||||
// clear all package data
|
||||
assert.NoError(t, db.TruncateBeans(db.DefaultContext,
|
||||
&packages_model.Package{},
|
||||
@@ -250,17 +258,25 @@ func PrepareTestEnv(t testing.TB, skip ...int) func() {
|
||||
&packages_model.PackageCleanupRule{},
|
||||
))
|
||||
assert.NoError(t, storage.Clean(storage.Packages))
|
||||
}
|
||||
|
||||
func PrepareTestEnv(t testing.TB, skip ...int) func() {
|
||||
t.Helper()
|
||||
deferFn := PrintCurrentTest(t, util.OptionalArg(skip)+1)
|
||||
|
||||
// load database fixtures
|
||||
assert.NoError(t, unittest.LoadFixtures())
|
||||
|
||||
// do not add more Prepare* functions here, only call necessary ones in the related test functions
|
||||
PrepareGitRepoDirectory(t)
|
||||
PrepareLFSStorage(t)
|
||||
PrepareCleanPackageData(t)
|
||||
return deferFn
|
||||
}
|
||||
|
||||
func PrintCurrentTest(t testing.TB, skip ...int) func() {
|
||||
t.Helper()
|
||||
actualSkip := 1
|
||||
if len(skip) > 0 {
|
||||
actualSkip = skip[0] + 1
|
||||
}
|
||||
return testlogger.PrintCurrentTest(t, actualSkip)
|
||||
return testlogger.PrintCurrentTest(t, util.OptionalArg(skip)+1)
|
||||
}
|
||||
|
||||
// Printf takes a format and args and prints the string to os.Stdout
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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