diff --git a/routers/web/shared/actions/fixtures/TestRunnerDetails/action_runner.yml b/routers/web/shared/actions/fixtures/TestRunnerDetails/action_runner.yml new file mode 100644 index 0000000000..d783f83110 --- /dev/null +++ b/routers/web/shared/actions/fixtures/TestRunnerDetails/action_runner.yml @@ -0,0 +1,7 @@ +- + id: 1004 + uuid: "fb857e63-c0ce-4571-a6c9-fde26c128073" + name: "Global runner" + owner_id: 0 + repo_id: 0 + deleted: 0 diff --git a/routers/web/shared/actions/fixtures/TestRunnerDetails/action_task.yml b/routers/web/shared/actions/fixtures/TestRunnerDetails/action_task.yml new file mode 100644 index 0000000000..63a2d30deb --- /dev/null +++ b/routers/web/shared/actions/fixtures/TestRunnerDetails/action_task.yml @@ -0,0 +1,160 @@ +- + id: 1 + runner_id: 1004 + token_hash: a1 +- + id: 2 + runner_id: 1004 + token_hash: a2 +- + id: 3 + runner_id: 1004 + token_hash: a3 +- + id: 4 + runner_id: 1004 + token_hash: a4 +- + id: 5 + runner_id: 1004 + token_hash: a5 +- + id: 6 + runner_id: 1004 + token_hash: a6 +- + id: 7 + runner_id: 1004 + token_hash: a7 +- + id: 8 + runner_id: 1004 + token_hash: a8 +- + id: 9 + runner_id: 1004 + token_hash: a9 +- + id: 10 + runner_id: 1004 + token_hash: a10 +- + id: 11 + runner_id: 1004 + token_hash: a11 +- + id: 12 + runner_id: 1004 + token_hash: a12 +- + id: 13 + runner_id: 1004 + token_hash: a13 +- + id: 14 + runner_id: 1004 + token_hash: a14 +- + id: 15 + runner_id: 1004 + token_hash: a15 +- + id: 16 + runner_id: 1004 + token_hash: a16 +- + id: 17 + runner_id: 1004 + token_hash: a17 +- + id: 18 + runner_id: 1004 + token_hash: a18 +- + id: 19 + runner_id: 1004 + token_hash: a19 +- + id: 20 + runner_id: 1004 + token_hash: a20 +- + id: 21 + runner_id: 1004 + token_hash: a21 +- + id: 22 + runner_id: 1004 + token_hash: a22 +- + id: 23 + runner_id: 1004 + token_hash: a23 +- + id: 24 + runner_id: 1004 + token_hash: a24 +- + id: 25 + runner_id: 1004 + token_hash: a25 +- + id: 26 + runner_id: 1004 + token_hash: a26 +- + id: 27 + runner_id: 1004 + token_hash: a27 +- + id: 28 + runner_id: 1004 + token_hash: a28 +- + id: 29 + runner_id: 1004 + token_hash: a29 +- + id: 30 + runner_id: 1004 + token_hash: a30 +- + id: 31 + runner_id: 1004 + token_hash: a31 +- + id: 32 + runner_id: 1004 + token_hash: a32 +- + id: 33 + runner_id: 1004 + token_hash: a33 +- + id: 34 + runner_id: 1004 + token_hash: a34 +- + id: 35 + runner_id: 1004 + token_hash: a35 +- + id: 36 + runner_id: 1004 + token_hash: a36 +- + id: 37 + runner_id: 1004 + token_hash: a37 +- + id: 38 + runner_id: 1004 + token_hash: a38 +- + id: 39 + runner_id: 1004 + token_hash: a39 +- + id: 40 + runner_id: 1004 + token_hash: a40 diff --git a/routers/web/shared/actions/main_test.go b/routers/web/shared/actions/main_test.go new file mode 100644 index 0000000000..056f48b98d --- /dev/null +++ b/routers/web/shared/actions/main_test.go @@ -0,0 +1,17 @@ +// Copyright 2025 The Forgejo Authors. +// SPDX-License-Identifier: GPL-3.0-or-later + +package actions + +import ( + "testing" + + "forgejo.org/models/unittest" + + _ "forgejo.org/models" + _ "forgejo.org/models/forgefed" +) + +func TestMain(m *testing.M) { + unittest.MainTest(m) +} diff --git a/routers/web/shared/actions/runners.go b/routers/web/shared/actions/runners.go index 98a649d1d8..2ab6b2dadd 100644 --- a/routers/web/shared/actions/runners.go +++ b/routers/web/shared/actions/runners.go @@ -79,7 +79,6 @@ func RunnerDetails(ctx *context.Context, page int, runnerID, ownerID, repoID int Page: page, PageSize: 30, }, - Status: []actions_model.Status{actions_model.StatusUnknown}, // Unknown means all RunnerID: runner.ID, } diff --git a/routers/web/shared/actions/runners_test.go b/routers/web/shared/actions/runners_test.go new file mode 100644 index 0000000000..ad75d34ee6 --- /dev/null +++ b/routers/web/shared/actions/runners_test.go @@ -0,0 +1,47 @@ +// Copyright 2025 The Forgejo Authors. +// SPDX-License-Identifier: GPL-3.0-or-later + +package actions + +import ( + "net/http" + "testing" + + actions_model "forgejo.org/models/actions" + "forgejo.org/models/unittest" + user_model "forgejo.org/models/user" + "forgejo.org/services/contexttest" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestRunnerDetails(t *testing.T) { + defer unittest.OverrideFixtures("routers/web/shared/actions/fixtures/TestRunnerDetails")() + require.NoError(t, unittest.PrepareTestDatabase()) + + user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) + runner := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRunner{ID: 1004}) + + t.Run("permission denied", func(t *testing.T) { + ctx, resp := contexttest.MockContext(t, "/admin/actions/runners") + RunnerDetails(ctx, 1, runner.ID, user.ID, 0) + assert.Equal(t, http.StatusNotFound, resp.Code) + }) + + t.Run("first page", func(t *testing.T) { + ctx, resp := contexttest.MockContext(t, "/admin/actions/runners") + page := 1 + RunnerDetails(ctx, page, runner.ID, 0, 0) + require.Equal(t, http.StatusOK, resp.Code) + assert.Len(t, ctx.GetData()["Tasks"], 30) + }) + + t.Run("second and last page", func(t *testing.T) { + ctx, resp := contexttest.MockContext(t, "/admin/actions/runners") + page := 2 + RunnerDetails(ctx, page, runner.ID, 0, 0) + require.Equal(t, http.StatusOK, resp.Code) + assert.Len(t, ctx.GetData()["Tasks"], 10) + }) +}