mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-09-14 14:57:21 +00:00
fix!: use run ID instead of run Index in artifacts download web views
- the run ID used to download artifacts is absolute (ID) instead of being relative to the repository (Index) for compatibility with the url built and returned as `artifact-url` by the the upload-artifact@v4 action. - this is a breaking change because URLs to download artifacts previous saved/bookmarked and not yet expired expired are no longer working, they need to be looked up again by visiting the job web page. - add unit tests for getRunByID(). - RepoActionView.test.js verifies the download URL is built using the run ID. - lAdd integration tests to verify the RunID is set as expected in the template used by RepoActionView.vue. Refs https://code.forgejo.org/forgejo/runner/issues/187
This commit is contained in:
parent
f7b0eb16c8
commit
b047a60a09
9 changed files with 233 additions and 19 deletions
|
@ -4,6 +4,8 @@
|
|||
package integration
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
@ -58,29 +60,53 @@ func TestActionsViewArtifactDeletion(t *testing.T) {
|
|||
func TestActionViewsArtifactDownload(t *testing.T) {
|
||||
defer prepareTestEnvActionsArtifacts(t)()
|
||||
|
||||
assertDataAttrs := func(t *testing.T, body *bytes.Buffer, runID int64) {
|
||||
t.Helper()
|
||||
run := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{ID: runID})
|
||||
htmlDoc := NewHTMLParser(t, body)
|
||||
selector := "#repo-action-view"
|
||||
htmlDoc.AssertAttrEqual(t, selector, "data-run-id", fmt.Sprintf("%d", run.ID))
|
||||
htmlDoc.AssertAttrEqual(t, selector, "data-run-index", fmt.Sprintf("%d", run.Index))
|
||||
}
|
||||
|
||||
t.Run("V3", func(t *testing.T) {
|
||||
req := NewRequest(t, "GET", "/user5/repo4/actions/runs/187/artifacts")
|
||||
runIndex := 187
|
||||
runID := int64(791)
|
||||
|
||||
req := NewRequest(t, "GET", fmt.Sprintf("/user5/repo4/actions/runs/%d/artifacts", runIndex))
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
assert.JSONEq(t, `{"artifacts":[{"name":"multi-file-download","size":2048,"status":"completed"}]}`, strings.TrimSuffix(resp.Body.String(), "\n"))
|
||||
|
||||
req = NewRequest(t, "GET", "/user5/repo4/actions/runs/187/artifacts/multi-file-download")
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("/user5/repo4/actions/runs/%d", runIndex))
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
assertDataAttrs(t, resp.Body, runID)
|
||||
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("/user5/repo4/actions/runs/%d/artifacts/multi-file-download", runID))
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
assert.Contains(t, resp.Header().Get("content-disposition"), "multi-file-download.zip")
|
||||
})
|
||||
|
||||
t.Run("V4", func(t *testing.T) {
|
||||
req := NewRequest(t, "GET", "/user5/repo4/actions/runs/188/artifacts")
|
||||
runIndex := 188
|
||||
runID := int64(792)
|
||||
|
||||
req := NewRequest(t, "GET", fmt.Sprintf("/user5/repo4/actions/runs/%d/artifacts", runIndex))
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
assert.JSONEq(t, `{"artifacts":[{"name":"artifact-v4-download","size":1024,"status":"completed"}]}`, strings.TrimSuffix(resp.Body.String(), "\n"))
|
||||
|
||||
req = NewRequest(t, "GET", "/user5/repo4/actions/runs/188/artifacts/artifact-v4-download")
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("/user5/repo4/actions/runs/%d", runIndex))
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
assertDataAttrs(t, resp.Body, runID)
|
||||
|
||||
download := fmt.Sprintf("/user5/repo4/actions/runs/%d/artifacts/artifact-v4-download", runID)
|
||||
req = NewRequest(t, "GET", download)
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
assert.Equal(t, "bytes", resp.Header().Get("accept-ranges"))
|
||||
assert.Contains(t, resp.Header().Get("content-disposition"), "artifact-v4-download.zip")
|
||||
assert.Equal(t, strings.Repeat("D", 1024), resp.Body.String())
|
||||
|
||||
// Partial artifact download
|
||||
req = NewRequest(t, "GET", "/user5/repo4/actions/runs/188/artifacts/artifact-v4-download").SetHeader("range", "bytes=0-99")
|
||||
req = NewRequest(t, "GET", download).SetHeader("range", "bytes=0-99")
|
||||
resp = MakeRequest(t, req, http.StatusPartialContent)
|
||||
assert.Equal(t, "bytes 0-99/1024", resp.Header().Get("content-range"))
|
||||
assert.Equal(t, strings.Repeat("D", 100), resp.Body.String())
|
||||
|
|
|
@ -26,6 +26,17 @@ func NewHTMLParser(t testing.TB, body *bytes.Buffer) *HTMLDoc {
|
|||
return &HTMLDoc{doc: doc}
|
||||
}
|
||||
|
||||
func (doc *HTMLDoc) AssertAttrEqual(t testing.TB, selector, attr, expected string) bool {
|
||||
t.Helper()
|
||||
selection := doc.doc.Find(selector)
|
||||
require.NotEmpty(t, selection, selector)
|
||||
|
||||
actual, exists := selection.Attr(attr)
|
||||
require.True(t, exists, "%s not found in %s", attr, selection.Text())
|
||||
|
||||
return assert.Equal(t, expected, actual)
|
||||
}
|
||||
|
||||
// GetInputValueByID for get input value by id
|
||||
func (doc *HTMLDoc) GetInputValueByID(id string) string {
|
||||
text, _ := doc.doc.Find("#" + id).Attr("value")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue