mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-09-13 14:27:17 +00:00
chore: refactor the web UI tests for the actions run
- create tests/integration/actions_view_test.go - extract TestActionsArtifactDeletion from actions_route_test.go - extract tests misplaced in - api_actions_artifact_test.go - api_actions_artifact_v4_test.go - add a tests for the /{owner}/{repo}/actions/runs/{run_index}/artifacts because it is useful for debugging
This commit is contained in:
parent
014bf73db8
commit
f7b0eb16c8
4 changed files with 88 additions and 60 deletions
|
@ -146,38 +146,3 @@ func TestActionsWebRouteLatestRun(t *testing.T) {
|
|||
assert.Equal(t, workflow.HTMLURL(), resp.Header().Get("Location"))
|
||||
})
|
||||
}
|
||||
|
||||
func TestActionsWebRouteArtifactDeletion(t *testing.T) {
|
||||
onGiteaRun(t, func(t *testing.T, u *url.URL) {
|
||||
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
|
||||
// create the repo
|
||||
repo, _, f := tests.CreateDeclarativeRepo(t, user2, "",
|
||||
[]unit_model.Type{unit_model.TypeActions}, nil,
|
||||
[]*files_service.ChangeRepoFile{
|
||||
{
|
||||
Operation: "create",
|
||||
TreePath: ".gitea/workflows/pr.yml",
|
||||
ContentReader: strings.NewReader("name: test\non:\n push:\njobs:\n test:\n runs-on: ubuntu-latest\n steps:\n - run: echo helloworld\n"),
|
||||
},
|
||||
},
|
||||
)
|
||||
defer f()
|
||||
|
||||
// a run has been created
|
||||
assert.Equal(t, 1, unittest.GetCount(t, &actions_model.ActionRun{RepoID: repo.ID}))
|
||||
|
||||
// Load the run we just created
|
||||
run := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{RepoID: repo.ID})
|
||||
err := run.LoadAttributes(t.Context())
|
||||
require.NoError(t, err)
|
||||
|
||||
// Visit it's web view
|
||||
req := NewRequest(t, "GET", run.HTMLURL())
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
|
||||
// Assert that the artifact deletion markup exists
|
||||
htmlDoc.AssertElement(t, "[data-locale-confirm-delete-artifact]", true)
|
||||
})
|
||||
}
|
||||
|
|
88
tests/integration/actions_view_test.go
Normal file
88
tests/integration/actions_view_test.go
Normal file
|
@ -0,0 +1,88 @@
|
|||
// Copyright 2025 The Forgejo Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package integration
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
actions_model "forgejo.org/models/actions"
|
||||
unit_model "forgejo.org/models/unit"
|
||||
"forgejo.org/models/unittest"
|
||||
user_model "forgejo.org/models/user"
|
||||
files_service "forgejo.org/services/repository/files"
|
||||
"forgejo.org/tests"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestActionsViewArtifactDeletion(t *testing.T) {
|
||||
onGiteaRun(t, func(t *testing.T, u *url.URL) {
|
||||
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
|
||||
// create the repo
|
||||
repo, _, f := tests.CreateDeclarativeRepo(t, user2, "",
|
||||
[]unit_model.Type{unit_model.TypeActions}, nil,
|
||||
[]*files_service.ChangeRepoFile{
|
||||
{
|
||||
Operation: "create",
|
||||
TreePath: ".gitea/workflows/pr.yml",
|
||||
ContentReader: strings.NewReader("name: test\non:\n push:\njobs:\n test:\n runs-on: ubuntu-latest\n steps:\n - run: echo helloworld\n"),
|
||||
},
|
||||
},
|
||||
)
|
||||
defer f()
|
||||
|
||||
// a run has been created
|
||||
assert.Equal(t, 1, unittest.GetCount(t, &actions_model.ActionRun{RepoID: repo.ID}))
|
||||
|
||||
// Load the run we just created
|
||||
run := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{RepoID: repo.ID})
|
||||
err := run.LoadAttributes(t.Context())
|
||||
require.NoError(t, err)
|
||||
|
||||
// Visit it's web view
|
||||
req := NewRequest(t, "GET", run.HTMLURL())
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
|
||||
// Assert that the artifact deletion markup exists
|
||||
htmlDoc.AssertElement(t, "[data-locale-confirm-delete-artifact]", true)
|
||||
})
|
||||
}
|
||||
|
||||
func TestActionViewsArtifactDownload(t *testing.T) {
|
||||
defer prepareTestEnvActionsArtifacts(t)()
|
||||
|
||||
t.Run("V3", func(t *testing.T) {
|
||||
req := NewRequest(t, "GET", "/user5/repo4/actions/runs/187/artifacts")
|
||||
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")
|
||||
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")
|
||||
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")
|
||||
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")
|
||||
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())
|
||||
})
|
||||
}
|
|
@ -267,11 +267,6 @@ func TestActionsArtifactDownloadMultiFiles(t *testing.T) {
|
|||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
assert.Equal(t, strings.Repeat(bodyChar, 1024), resp.Body.String())
|
||||
}
|
||||
|
||||
// Download artifact via user-facing URL
|
||||
req = NewRequest(t, "GET", "/user5/repo4/actions/runs/187/artifacts/multi-file-download")
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
assert.Contains(t, resp.Header().Get("content-disposition"), "multi-file-download.zip")
|
||||
}
|
||||
|
||||
func TestActionsArtifactUploadWithRetentionDays(t *testing.T) {
|
||||
|
|
|
@ -339,20 +339,6 @@ func TestActionsArtifactV4DownloadSingle(t *testing.T) {
|
|||
body := strings.Repeat("D", 1024)
|
||||
assert.Equal(t, "bytes", resp.Header().Get("accept-ranges"))
|
||||
assert.Equal(t, body, resp.Body.String())
|
||||
|
||||
// Download artifact via user-facing URL
|
||||
req = NewRequest(t, "GET", "/user5/repo4/actions/runs/188/artifacts/artifact-v4-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, body, resp.Body.String())
|
||||
|
||||
// Partial artifact download
|
||||
req = NewRequest(t, "GET", "/user5/repo4/actions/runs/188/artifacts/artifact-v4-download").SetHeader("range", "bytes=0-99")
|
||||
resp = MakeRequest(t, req, http.StatusPartialContent)
|
||||
body = strings.Repeat("D", 100)
|
||||
assert.Equal(t, "bytes 0-99/1024", resp.Header().Get("content-range"))
|
||||
assert.Equal(t, body, resp.Body.String())
|
||||
}
|
||||
|
||||
func TestActionsArtifactV4DownloadRange(t *testing.T) {
|
||||
|
@ -378,12 +364,6 @@ func TestActionsArtifactV4DownloadRange(t *testing.T) {
|
|||
resp = MakeRequest(t, req, http.StatusPartialContent)
|
||||
assert.Equal(t, "bytes 100-199/1024", resp.Header().Get("content-range"))
|
||||
assert.Equal(t, bstr, resp.Body.String())
|
||||
|
||||
// Download (user-facing API)
|
||||
req = NewRequest(t, "GET", "/user5/repo4/actions/runs/188/artifacts/artifact-v4-download").SetHeader("range", "bytes=100-199")
|
||||
resp = MakeRequest(t, req, http.StatusPartialContent)
|
||||
assert.Equal(t, "bytes 100-199/1024", resp.Header().Get("content-range"))
|
||||
assert.Equal(t, bstr, resp.Body.String())
|
||||
}
|
||||
|
||||
func TestActionsArtifactV4Delete(t *testing.T) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue