summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/api_admin_actions_test.go39
-rw-r--r--tests/integration/api_org_actions_test.go38
-rw-r--r--tests/integration/api_repo_actions_test.go43
-rw-r--r--tests/integration/api_user_actions_test.go38
4 files changed, 158 insertions, 0 deletions
diff --git a/tests/integration/api_admin_actions_test.go b/tests/integration/api_admin_actions_test.go
new file mode 100644
index 0000000000..22590dc4c4
--- /dev/null
+++ b/tests/integration/api_admin_actions_test.go
@@ -0,0 +1,39 @@
+// Copyright 2024 The Forgejo Authors c/o Codeberg e.V.. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package integration
+
+import (
+ "fmt"
+ "net/http"
+ "testing"
+
+ actions_model "code.gitea.io/gitea/models/actions"
+ auth_model "code.gitea.io/gitea/models/auth"
+ "code.gitea.io/gitea/models/unittest"
+ "code.gitea.io/gitea/routers/api/v1/shared"
+ "code.gitea.io/gitea/tests"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestAPISearchActionJobs_GlobalRunner(t *testing.T) {
+ defer tests.PrepareTestEnv(t)()
+
+ job := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRunJob{ID: 393})
+ adminUsername := "user1"
+ token := getUserToken(t, adminUsername, auth_model.AccessTokenScopeWriteAdmin)
+
+ req := NewRequest(
+ t,
+ "GET",
+ fmt.Sprintf("/api/v1/admin/runners/jobs?labels=%s", "ubuntu-latest"),
+ ).AddTokenAuth(token)
+ res := MakeRequest(t, req, http.StatusOK)
+
+ var jobs shared.RunJobList
+ DecodeJSON(t, res, &jobs)
+
+ assert.Len(t, jobs.Body, 1)
+ assert.EqualValues(t, job.ID, jobs.Body[0].ID)
+}
diff --git a/tests/integration/api_org_actions_test.go b/tests/integration/api_org_actions_test.go
new file mode 100644
index 0000000000..c8ebbdf293
--- /dev/null
+++ b/tests/integration/api_org_actions_test.go
@@ -0,0 +1,38 @@
+// Copyright 2025 The Forgejo Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package integration
+
+import (
+ "fmt"
+ "net/http"
+ "testing"
+
+ actions_model "code.gitea.io/gitea/models/actions"
+ auth_model "code.gitea.io/gitea/models/auth"
+ "code.gitea.io/gitea/models/unittest"
+ "code.gitea.io/gitea/routers/api/v1/shared"
+ "code.gitea.io/gitea/tests"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestAPISearchActionJobs_OrgRunner(t *testing.T) {
+ defer tests.PrepareTestEnv(t)()
+
+ session := loginUser(t, "user1")
+ token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteOrganization)
+
+ job := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRunJob{ID: 395})
+
+ req := NewRequest(t, "GET",
+ fmt.Sprintf("/api/v1/orgs/org3/actions/runners/jobs?labels=%s", "fedora")).
+ AddTokenAuth(token)
+ res := MakeRequest(t, req, http.StatusOK)
+
+ var jobs shared.RunJobList
+ DecodeJSON(t, res, &jobs)
+
+ assert.Len(t, jobs.Body, 1)
+ assert.EqualValues(t, job.ID, jobs.Body[0].ID)
+}
diff --git a/tests/integration/api_repo_actions_test.go b/tests/integration/api_repo_actions_test.go
new file mode 100644
index 0000000000..9c3b6aa2b6
--- /dev/null
+++ b/tests/integration/api_repo_actions_test.go
@@ -0,0 +1,43 @@
+// Copyright 2025 The Forgejo Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package integration
+
+import (
+ "net/http"
+ "testing"
+
+ actions_model "code.gitea.io/gitea/models/actions"
+ auth_model "code.gitea.io/gitea/models/auth"
+ repo_model "code.gitea.io/gitea/models/repo"
+ "code.gitea.io/gitea/models/unittest"
+ user_model "code.gitea.io/gitea/models/user"
+ "code.gitea.io/gitea/routers/api/v1/shared"
+ "code.gitea.io/gitea/tests"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestAPISearchActionJobs_RepoRunner(t *testing.T) {
+ defer tests.PrepareTestEnv(t)()
+
+ repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
+ user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
+ token := getUserToken(t, user2.LowerName, auth_model.AccessTokenScopeWriteRepository)
+ job := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRunJob{ID: 393})
+
+ req := NewRequestf(
+ t,
+ "GET",
+ "/api/v1/repos/%s/%s/actions/runners/jobs?labels=%s",
+ repo.OwnerName, repo.Name,
+ "ubuntu-latest",
+ ).AddTokenAuth(token)
+ res := MakeRequest(t, req, http.StatusOK)
+
+ var jobs shared.RunJobList
+ DecodeJSON(t, res, &jobs)
+
+ assert.Len(t, jobs.Body, 1)
+ assert.EqualValues(t, job.ID, jobs.Body[0].ID)
+}
diff --git a/tests/integration/api_user_actions_test.go b/tests/integration/api_user_actions_test.go
new file mode 100644
index 0000000000..f9c9c1df4e
--- /dev/null
+++ b/tests/integration/api_user_actions_test.go
@@ -0,0 +1,38 @@
+// Copyright 2025 The Forgejo Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package integration
+
+import (
+ "fmt"
+ "net/http"
+ "testing"
+
+ actions_model "code.gitea.io/gitea/models/actions"
+ auth_model "code.gitea.io/gitea/models/auth"
+ "code.gitea.io/gitea/models/unittest"
+ "code.gitea.io/gitea/routers/api/v1/shared"
+ "code.gitea.io/gitea/tests"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestAPISearchActionJobs_UserRunner(t *testing.T) {
+ defer tests.PrepareTestEnv(t)()
+
+ normalUsername := "user2"
+ session := loginUser(t, normalUsername)
+ token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteUser)
+ job := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRunJob{ID: 394})
+
+ req := NewRequest(t, "GET",
+ fmt.Sprintf("/api/v1/user/actions/runners/jobs?labels=%s", "debian-latest")).
+ AddTokenAuth(token)
+ res := MakeRequest(t, req, http.StatusOK)
+
+ var jobs shared.RunJobList
+ DecodeJSON(t, res, &jobs)
+
+ assert.Len(t, jobs.Body, 1)
+ assert.EqualValues(t, job.ID, jobs.Body[0].ID)
+}