mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-23 06:43:34 +01:00
Add artifacts test fixture (#30300)
Closes https://github.com/go-gitea/gitea/issues/30296 - Adds a DB fixture for actions artifacts - Adds artifacts test files - Clears artifacts test files between each run - Note: I initially initialized the artifacts only for artifacts tests, but because the files are small it only takes ~8ms, so I changed it to always run in test setup for simplicity - Fix some otherwise flaky tests by making them not depend on previous tests (cherry picked from commit 66971e591e5dddd5b6dc1572ac48f4e4ab29b8e0) Conflicts: - tests/integration/api_actions_artifact_test.go Conflict resolved by manually changing the tested artifact name from "artifact" to "artifact-download" - tests/integration/api_actions_artifact_v4_test.go Conflict resolved by manually updating the tested artifact names, and adjusting the test case only present in our tree. - tests/test_utils.go Resolved by manually copying the added function.
This commit is contained in:
parent
6b74043b85
commit
748ae10e7c
9 changed files with 147 additions and 45 deletions
71
models/fixtures/action_artifact.yml
Normal file
71
models/fixtures/action_artifact.yml
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
-
|
||||||
|
id: 1
|
||||||
|
run_id: 791
|
||||||
|
runner_id: 1
|
||||||
|
repo_id: 4
|
||||||
|
owner_id: 1
|
||||||
|
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
|
||||||
|
storage_path: "26/1/1712166500347189545.chunk"
|
||||||
|
file_size: 1024
|
||||||
|
file_compressed_size: 1024
|
||||||
|
content_encoding: ""
|
||||||
|
artifact_path: "abc.txt"
|
||||||
|
artifact_name: "artifact-download"
|
||||||
|
status: 1
|
||||||
|
created_unix: 1712338649
|
||||||
|
updated_unix: 1712338649
|
||||||
|
expired_unix: 1720114649
|
||||||
|
|
||||||
|
-
|
||||||
|
id: 19
|
||||||
|
run_id: 791
|
||||||
|
runner_id: 1
|
||||||
|
repo_id: 4
|
||||||
|
owner_id: 1
|
||||||
|
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
|
||||||
|
storage_path: "26/19/1712348022422036662.chunk"
|
||||||
|
file_size: 1024
|
||||||
|
file_compressed_size: 1024
|
||||||
|
content_encoding: ""
|
||||||
|
artifact_path: "abc.txt"
|
||||||
|
artifact_name: "multi-file-download"
|
||||||
|
status: 2
|
||||||
|
created_unix: 1712348022
|
||||||
|
updated_unix: 1712348022
|
||||||
|
expired_unix: 1720124022
|
||||||
|
|
||||||
|
-
|
||||||
|
id: 20
|
||||||
|
run_id: 791
|
||||||
|
runner_id: 1
|
||||||
|
repo_id: 4
|
||||||
|
owner_id: 1
|
||||||
|
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
|
||||||
|
storage_path: "26/20/1712348022423431524.chunk"
|
||||||
|
file_size: 1024
|
||||||
|
file_compressed_size: 1024
|
||||||
|
content_encoding: ""
|
||||||
|
artifact_path: "xyz/def.txt"
|
||||||
|
artifact_name: "multi-file-download"
|
||||||
|
status: 2
|
||||||
|
created_unix: 1712348022
|
||||||
|
updated_unix: 1712348022
|
||||||
|
expired_unix: 1720124022
|
||||||
|
|
||||||
|
-
|
||||||
|
id: 22
|
||||||
|
run_id: 792
|
||||||
|
runner_id: 1
|
||||||
|
repo_id: 4
|
||||||
|
owner_id: 1
|
||||||
|
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
|
||||||
|
storage_path: "27/5/1730330775594233150.chunk"
|
||||||
|
file_size: 1024
|
||||||
|
file_compressed_size: 1024
|
||||||
|
content_encoding: "application/zip"
|
||||||
|
artifact_path: "artifact-v4-download.zip"
|
||||||
|
artifact_name: "artifact-v4-download"
|
||||||
|
status: 2
|
||||||
|
created_unix: 1730330775
|
||||||
|
updated_unix: 1730330775
|
||||||
|
expired_unix: 1738106775
|
|
@ -131,7 +131,7 @@ var (
|
||||||
ActionsArtifacts ObjectStorage = UninitializedStorage
|
ActionsArtifacts ObjectStorage = UninitializedStorage
|
||||||
)
|
)
|
||||||
|
|
||||||
// Init init the stoarge
|
// Init init the storage
|
||||||
func Init() error {
|
func Init() error {
|
||||||
for _, f := range []func() error{
|
for _, f := range []func() error{
|
||||||
initAttachments,
|
initAttachments,
|
||||||
|
|
|
@ -38,21 +38,21 @@ func TestActionsArtifactUploadSingleFile(t *testing.T) {
|
||||||
|
|
||||||
// get upload url
|
// get upload url
|
||||||
idx := strings.Index(uploadResp.FileContainerResourceURL, "/api/actions_pipeline/_apis/pipelines/")
|
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
|
// upload artifact chunk
|
||||||
body := strings.Repeat("A", 1024)
|
body := strings.Repeat("C", 1024)
|
||||||
req = NewRequestWithBody(t, "PUT", url, strings.NewReader(body)).
|
req = NewRequestWithBody(t, "PUT", url, strings.NewReader(body)).
|
||||||
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a").
|
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a").
|
||||||
SetHeader("Content-Range", "bytes 0-1023/1024").
|
SetHeader("Content-Range", "bytes 0-1023/1024").
|
||||||
SetHeader("x-tfs-filelength", "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)
|
MakeRequest(t, req, http.StatusOK)
|
||||||
|
|
||||||
t.Logf("Create artifact confirm")
|
t.Logf("Create artifact confirm")
|
||||||
|
|
||||||
// confirm artifact upload
|
// 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")
|
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
||||||
MakeRequest(t, req, http.StatusOK)
|
MakeRequest(t, req, http.StatusOK)
|
||||||
}
|
}
|
||||||
|
@ -115,29 +115,40 @@ func TestActionsArtifactDownload(t *testing.T) {
|
||||||
resp := MakeRequest(t, req, http.StatusOK)
|
resp := MakeRequest(t, req, http.StatusOK)
|
||||||
var listResp listArtifactsResponse
|
var listResp listArtifactsResponse
|
||||||
DecodeJSON(t, resp, &listResp)
|
DecodeJSON(t, resp, &listResp)
|
||||||
assert.Equal(t, int64(1), listResp.Count)
|
assert.Equal(t, int64(2), 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")
|
|
||||||
|
|
||||||
idx := strings.Index(listResp.Value[0].FileContainerResourceURL, "/api/actions_pipeline/_apis/pipelines/")
|
// Return list might be in any order. Get one file.
|
||||||
url := listResp.Value[0].FileContainerResourceURL[idx+1:] + "?itemPath=artifact"
|
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).
|
req = NewRequest(t, "GET", url).
|
||||||
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
||||||
resp = MakeRequest(t, req, http.StatusOK)
|
resp = MakeRequest(t, req, http.StatusOK)
|
||||||
var downloadResp downloadArtifactResponse
|
var downloadResp downloadArtifactResponse
|
||||||
DecodeJSON(t, resp, &downloadResp)
|
DecodeJSON(t, resp, &downloadResp)
|
||||||
assert.Len(t, downloadResp.Value, 1)
|
assert.Len(t, downloadResp.Value, 1)
|
||||||
assert.Equal(t, "artifact/abc.txt", downloadResp.Value[0].Path)
|
assert.Equal(t, "artifact-download/abc.txt", downloadResp.Value[artifactIdx].Path)
|
||||||
assert.Equal(t, "file", downloadResp.Value[0].ItemType)
|
assert.Equal(t, "file", downloadResp.Value[artifactIdx].ItemType)
|
||||||
assert.Contains(t, downloadResp.Value[0].ContentLocation, "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts")
|
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/")
|
idx = strings.Index(downloadResp.Value[artifactIdx].ContentLocation, "/api/actions_pipeline/_apis/pipelines/")
|
||||||
url = downloadResp.Value[0].ContentLocation[idx:]
|
url = downloadResp.Value[artifactIdx].ContentLocation[idx:]
|
||||||
req = NewRequest(t, "GET", url).
|
req = NewRequest(t, "GET", url).
|
||||||
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
||||||
resp = MakeRequest(t, req, http.StatusOK)
|
resp = MakeRequest(t, req, http.StatusOK)
|
||||||
|
|
||||||
body := strings.Repeat("A", 1024)
|
body := strings.Repeat("A", 1024)
|
||||||
assert.Equal(t, resp.Body.String(), body)
|
assert.Equal(t, body, resp.Body.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestActionsArtifactUploadMultipleFile(t *testing.T) {
|
func TestActionsArtifactUploadMultipleFile(t *testing.T) {
|
||||||
|
@ -163,14 +174,14 @@ func TestActionsArtifactUploadMultipleFile(t *testing.T) {
|
||||||
|
|
||||||
files := []uploadingFile{
|
files := []uploadingFile{
|
||||||
{
|
{
|
||||||
Path: "abc.txt",
|
Path: "abc-3.txt",
|
||||||
Content: strings.Repeat("A", 1024),
|
Content: strings.Repeat("D", 1024),
|
||||||
MD5: "1HsSe8LeLWh93ILaw1TEFQ==",
|
MD5: "9nqj7E8HZmfQtPifCJ5Zww==",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Path: "xyz/def.txt",
|
Path: "xyz/def-2.txt",
|
||||||
Content: strings.Repeat("B", 1024),
|
Content: strings.Repeat("E", 1024),
|
||||||
MD5: "6fgADK/7zjadf+6cB9Q1CQ==",
|
MD5: "/s1kKvxeHlUX85vaTaVxuA==",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,7 +210,7 @@ func TestActionsArtifactUploadMultipleFile(t *testing.T) {
|
||||||
func TestActionsArtifactDownloadMultiFiles(t *testing.T) {
|
func TestActionsArtifactDownloadMultiFiles(t *testing.T) {
|
||||||
defer tests.PrepareTestEnv(t)()
|
defer tests.PrepareTestEnv(t)()
|
||||||
|
|
||||||
const testArtifactName = "multi-files"
|
const testArtifactName = "multi-file-download"
|
||||||
|
|
||||||
req := NewRequest(t, "GET", "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts").
|
req := NewRequest(t, "GET", "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts").
|
||||||
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
||||||
|
@ -226,7 +237,7 @@ func TestActionsArtifactDownloadMultiFiles(t *testing.T) {
|
||||||
DecodeJSON(t, resp, &downloadResp)
|
DecodeJSON(t, resp, &downloadResp)
|
||||||
assert.Len(t, downloadResp.Value, 2)
|
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 {
|
for _, v := range downloadResp.Value {
|
||||||
var bodyChar string
|
var bodyChar string
|
||||||
var path string
|
var path string
|
||||||
|
@ -247,8 +258,7 @@ func TestActionsArtifactDownloadMultiFiles(t *testing.T) {
|
||||||
req = NewRequest(t, "GET", url).
|
req = NewRequest(t, "GET", url).
|
||||||
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
||||||
resp = MakeRequest(t, req, http.StatusOK)
|
resp = MakeRequest(t, req, http.StatusOK)
|
||||||
body := strings.Repeat(bodyChar, 1024)
|
assert.Equal(t, strings.Repeat(bodyChar, 1024), resp.Body.String())
|
||||||
assert.Equal(t, resp.Body.String(), body)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,7 +310,7 @@ func TestActionsArtifactOverwrite(t *testing.T) {
|
||||||
DecodeJSON(t, resp, &listResp)
|
DecodeJSON(t, resp, &listResp)
|
||||||
|
|
||||||
idx := strings.Index(listResp.Value[0].FileContainerResourceURL, "/api/actions_pipeline/_apis/pipelines/")
|
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).
|
req = NewRequest(t, "GET", url).
|
||||||
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
||||||
resp = MakeRequest(t, req, http.StatusOK)
|
resp = MakeRequest(t, req, http.StatusOK)
|
||||||
|
@ -320,14 +330,14 @@ func TestActionsArtifactOverwrite(t *testing.T) {
|
||||||
// upload same artifact, it uses 4096 B
|
// upload same artifact, it uses 4096 B
|
||||||
req := NewRequestWithJSON(t, "POST", "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts", getUploadArtifactRequest{
|
req := NewRequestWithJSON(t, "POST", "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts", getUploadArtifactRequest{
|
||||||
Type: "actions_storage",
|
Type: "actions_storage",
|
||||||
Name: "artifact",
|
Name: "artifact-download",
|
||||||
}).AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
}).AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
||||||
resp := MakeRequest(t, req, http.StatusOK)
|
resp := MakeRequest(t, req, http.StatusOK)
|
||||||
var uploadResp uploadArtifactResponse
|
var uploadResp uploadArtifactResponse
|
||||||
DecodeJSON(t, resp, &uploadResp)
|
DecodeJSON(t, resp, &uploadResp)
|
||||||
|
|
||||||
idx := strings.Index(uploadResp.FileContainerResourceURL, "/api/actions_pipeline/_apis/pipelines/")
|
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)
|
body := strings.Repeat("B", 4096)
|
||||||
req = NewRequestWithBody(t, "PUT", url, strings.NewReader(body)).
|
req = NewRequestWithBody(t, "PUT", url, strings.NewReader(body)).
|
||||||
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a").
|
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a").
|
||||||
|
@ -337,7 +347,7 @@ func TestActionsArtifactOverwrite(t *testing.T) {
|
||||||
MakeRequest(t, req, http.StatusOK)
|
MakeRequest(t, req, http.StatusOK)
|
||||||
|
|
||||||
// confirm artifact upload
|
// 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")
|
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
||||||
MakeRequest(t, req, http.StatusOK)
|
MakeRequest(t, req, http.StatusOK)
|
||||||
}
|
}
|
||||||
|
@ -352,15 +362,15 @@ func TestActionsArtifactOverwrite(t *testing.T) {
|
||||||
|
|
||||||
var uploadedItem listArtifactsResponseItem
|
var uploadedItem listArtifactsResponseItem
|
||||||
for _, item := range listResp.Value {
|
for _, item := range listResp.Value {
|
||||||
if item.Name == "artifact" {
|
if item.Name == "artifact-download" {
|
||||||
uploadedItem = item
|
uploadedItem = item
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert.Equal(t, "artifact", uploadedItem.Name)
|
assert.Equal(t, "artifact-download", uploadedItem.Name)
|
||||||
|
|
||||||
idx := strings.Index(uploadedItem.FileContainerResourceURL, "/api/actions_pipeline/_apis/pipelines/")
|
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).
|
req = NewRequest(t, "GET", url).
|
||||||
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
||||||
resp = MakeRequest(t, req, http.StatusOK)
|
resp = MakeRequest(t, req, http.StatusOK)
|
||||||
|
|
|
@ -313,7 +313,7 @@ func TestActionsArtifactV4DownloadSingle(t *testing.T) {
|
||||||
|
|
||||||
// acquire artifact upload url
|
// acquire artifact upload url
|
||||||
req := NewRequestWithBody(t, "POST", "/twirp/github.actions.results.api.v1.ArtifactService/ListArtifacts", toProtoJSON(&actions.ListArtifactsRequest{
|
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",
|
WorkflowRunBackendId: "792",
|
||||||
WorkflowJobRunBackendId: "193",
|
WorkflowJobRunBackendId: "193",
|
||||||
})).AddTokenAuth(token)
|
})).AddTokenAuth(token)
|
||||||
|
@ -324,7 +324,7 @@ func TestActionsArtifactV4DownloadSingle(t *testing.T) {
|
||||||
|
|
||||||
// confirm artifact upload
|
// confirm artifact upload
|
||||||
req = NewRequestWithBody(t, "POST", "/twirp/github.actions.results.api.v1.ArtifactService/GetSignedArtifactURL", toProtoJSON(&actions.GetSignedArtifactURLRequest{
|
req = NewRequestWithBody(t, "POST", "/twirp/github.actions.results.api.v1.ArtifactService/GetSignedArtifactURL", toProtoJSON(&actions.GetSignedArtifactURLRequest{
|
||||||
Name: "artifact",
|
Name: "artifact-v4-download",
|
||||||
WorkflowRunBackendId: "792",
|
WorkflowRunBackendId: "792",
|
||||||
WorkflowJobRunBackendId: "193",
|
WorkflowJobRunBackendId: "193",
|
||||||
})).
|
})).
|
||||||
|
@ -336,20 +336,20 @@ func TestActionsArtifactV4DownloadSingle(t *testing.T) {
|
||||||
|
|
||||||
req = NewRequest(t, "GET", finalizeResp.SignedUrl)
|
req = NewRequest(t, "GET", finalizeResp.SignedUrl)
|
||||||
resp = MakeRequest(t, req, http.StatusOK)
|
resp = MakeRequest(t, req, http.StatusOK)
|
||||||
body := strings.Repeat("A", 1024)
|
body := strings.Repeat("D", 1024)
|
||||||
assert.Equal(t, "bytes", resp.Header().Get("accept-ranges"))
|
assert.Equal(t, "bytes", resp.Header().Get("accept-ranges"))
|
||||||
assert.Equal(t, body, resp.Body.String())
|
assert.Equal(t, body, resp.Body.String())
|
||||||
|
|
||||||
// Download artifact via user-facing URL
|
// Download artifact via user-facing URL
|
||||||
req = NewRequest(t, "GET", "/user5/repo4/actions/runs/188/artifacts/artifact")
|
req = NewRequest(t, "GET", "/user5/repo4/actions/runs/188/artifacts/artifact-v4-download")
|
||||||
resp = MakeRequest(t, req, http.StatusOK)
|
resp = MakeRequest(t, req, http.StatusOK)
|
||||||
assert.Equal(t, "bytes", resp.Header().Get("accept-ranges"))
|
assert.Equal(t, "bytes", resp.Header().Get("accept-ranges"))
|
||||||
assert.Equal(t, body, resp.Body.String())
|
assert.Equal(t, body, resp.Body.String())
|
||||||
|
|
||||||
// Partial artifact download
|
// Partial artifact download
|
||||||
req = NewRequest(t, "GET", "/user5/repo4/actions/runs/188/artifacts/artifact").SetHeader("range", "bytes=0-99")
|
req = NewRequest(t, "GET", "/user5/repo4/actions/runs/188/artifacts/artifact-v4-download").SetHeader("range", "bytes=0-99")
|
||||||
resp = MakeRequest(t, req, http.StatusPartialContent)
|
resp = MakeRequest(t, req, http.StatusPartialContent)
|
||||||
body = strings.Repeat("A", 100)
|
body = strings.Repeat("D", 100)
|
||||||
assert.Equal(t, "bytes 0-99/1024", resp.Header().Get("content-range"))
|
assert.Equal(t, "bytes 0-99/1024", resp.Header().Get("content-range"))
|
||||||
assert.Equal(t, body, resp.Body.String())
|
assert.Equal(t, body, resp.Body.String())
|
||||||
}
|
}
|
||||||
|
@ -357,13 +357,13 @@ func TestActionsArtifactV4DownloadSingle(t *testing.T) {
|
||||||
func TestActionsArtifactV4DownloadRange(t *testing.T) {
|
func TestActionsArtifactV4DownloadRange(t *testing.T) {
|
||||||
defer tests.PrepareTestEnv(t)()
|
defer tests.PrepareTestEnv(t)()
|
||||||
|
|
||||||
bstr := strings.Repeat("B", 100)
|
bstr := strings.Repeat("D", 100)
|
||||||
body := strings.Repeat("A", 100) + bstr
|
body := strings.Repeat("A", 100) + bstr
|
||||||
token := uploadArtifact(t, body)
|
token := uploadArtifact(t, body)
|
||||||
|
|
||||||
// Download (Actions API)
|
// Download (Actions API)
|
||||||
req := NewRequestWithBody(t, "POST", "/twirp/github.actions.results.api.v1.ArtifactService/GetSignedArtifactURL", toProtoJSON(&actions.GetSignedArtifactURLRequest{
|
req := NewRequestWithBody(t, "POST", "/twirp/github.actions.results.api.v1.ArtifactService/GetSignedArtifactURL", toProtoJSON(&actions.GetSignedArtifactURLRequest{
|
||||||
Name: "artifact",
|
Name: "artifact-v4-download",
|
||||||
WorkflowRunBackendId: "792",
|
WorkflowRunBackendId: "792",
|
||||||
WorkflowJobRunBackendId: "193",
|
WorkflowJobRunBackendId: "193",
|
||||||
})).
|
})).
|
||||||
|
@ -375,13 +375,13 @@ func TestActionsArtifactV4DownloadRange(t *testing.T) {
|
||||||
|
|
||||||
req = NewRequest(t, "GET", finalizeResp.SignedUrl).SetHeader("range", "bytes=100-199")
|
req = NewRequest(t, "GET", finalizeResp.SignedUrl).SetHeader("range", "bytes=100-199")
|
||||||
resp = MakeRequest(t, req, http.StatusPartialContent)
|
resp = MakeRequest(t, req, http.StatusPartialContent)
|
||||||
assert.Equal(t, "bytes 100-199/200", resp.Header().Get("content-range"))
|
assert.Equal(t, "bytes 100-199/1024", resp.Header().Get("content-range"))
|
||||||
assert.Equal(t, bstr, resp.Body.String())
|
assert.Equal(t, bstr, resp.Body.String())
|
||||||
|
|
||||||
// Download (user-facing API)
|
// Download (user-facing API)
|
||||||
req = NewRequest(t, "GET", "/user5/repo4/actions/runs/188/artifacts/artifact").SetHeader("range", "bytes=100-199")
|
req = NewRequest(t, "GET", "/user5/repo4/actions/runs/188/artifacts/artifact-v4-download").SetHeader("range", "bytes=100-199")
|
||||||
resp = MakeRequest(t, req, http.StatusPartialContent)
|
resp = MakeRequest(t, req, http.StatusPartialContent)
|
||||||
assert.Equal(t, "bytes 100-199/200", resp.Header().Get("content-range"))
|
assert.Equal(t, "bytes 100-199/1024", resp.Header().Get("content-range"))
|
||||||
assert.Equal(t, bstr, resp.Body.String())
|
assert.Equal(t, bstr, resp.Body.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,7 +393,7 @@ func TestActionsArtifactV4Delete(t *testing.T) {
|
||||||
|
|
||||||
// delete artifact by name
|
// delete artifact by name
|
||||||
req := NewRequestWithBody(t, "POST", "/twirp/github.actions.results.api.v1.ArtifactService/DeleteArtifact", toProtoJSON(&actions.DeleteArtifactRequest{
|
req := NewRequestWithBody(t, "POST", "/twirp/github.actions.results.api.v1.ArtifactService/DeleteArtifact", toProtoJSON(&actions.DeleteArtifactRequest{
|
||||||
Name: "artifact",
|
Name: "artifact-v4-download",
|
||||||
WorkflowRunBackendId: "792",
|
WorkflowRunBackendId: "792",
|
||||||
WorkflowJobRunBackendId: "193",
|
WorkflowJobRunBackendId: "193",
|
||||||
})).AddTokenAuth(token)
|
})).AddTokenAuth(token)
|
||||||
|
|
|
@ -224,6 +224,20 @@ func cancelProcesses(t testing.TB, delay time.Duration) {
|
||||||
t.Logf("PrepareTestEnv: all processes cancelled within %s", time.Since(start))
|
t.Logf("PrepareTestEnv: all processes cancelled within %s", time.Since(start))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 PrepareTestEnv(t testing.TB, skip ...int) func() {
|
func PrepareTestEnv(t testing.TB, skip ...int) func() {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
ourSkip := 1
|
ourSkip := 1
|
||||||
|
@ -263,6 +277,9 @@ func PrepareTestEnv(t testing.TB, skip ...int) func() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialize actions artifact data
|
||||||
|
PrepareArtifactsStorage(t)
|
||||||
|
|
||||||
// load LFS object fixtures
|
// 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 we init it with the storage API)
|
||||||
lfsFixtures, err := storage.NewStorage(setting.LocalStorageType, &setting.Storage{
|
lfsFixtures, err := storage.NewStorage(setting.LocalStorageType, &setting.Storage{
|
||||||
|
|
1
tests/testdata/data/artifacts/26/1/1712166500347189545.chunk
vendored
Normal file
1
tests/testdata/data/artifacts/26/1/1712166500347189545.chunk
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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