diff --git a/tests/integration/actions_route_test.go b/tests/integration/actions_route_test.go index 521b379064..c058877806 100644 --- a/tests/integration/actions_route_test.go +++ b/tests/integration/actions_route_test.go @@ -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) - }) -} diff --git a/tests/integration/actions_view_test.go b/tests/integration/actions_view_test.go new file mode 100644 index 0000000000..bc76f976d5 --- /dev/null +++ b/tests/integration/actions_view_test.go @@ -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()) + }) +} diff --git a/tests/integration/api_actions_artifact_test.go b/tests/integration/api_actions_artifact_test.go index 4ecbbeb92c..1526ae3585 100644 --- a/tests/integration/api_actions_artifact_test.go +++ b/tests/integration/api_actions_artifact_test.go @@ -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) { diff --git a/tests/integration/api_actions_artifact_v4_test.go b/tests/integration/api_actions_artifact_v4_test.go index 716d9e1abe..02324ee73b 100644 --- a/tests/integration/api_actions_artifact_v4_test.go +++ b/tests/integration/api_actions_artifact_v4_test.go @@ -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) {