mirror of
https://github.com/go-gitea/gitea
synced 2025-07-07 11:07:20 +00:00
@ -41,8 +41,6 @@ func testActionsRunnerAdmin(t *testing.T) {
|
||||
runnerList := api.ActionRunnersResponse{}
|
||||
DecodeJSON(t, runnerListResp, &runnerList)
|
||||
|
||||
assert.Len(t, runnerList.Entries, 4)
|
||||
|
||||
idx := slices.IndexFunc(runnerList.Entries, func(e *api.ActionRunner) bool { return e.ID == 34349 })
|
||||
require.NotEqual(t, -1, idx)
|
||||
expectedRunner := runnerList.Entries[idx]
|
||||
@ -160,16 +158,20 @@ func testActionsRunnerOwner(t *testing.T) {
|
||||
runnerList := api.ActionRunnersResponse{}
|
||||
DecodeJSON(t, runnerListResp, &runnerList)
|
||||
|
||||
assert.Len(t, runnerList.Entries, 1)
|
||||
assert.Equal(t, "runner_to_be_deleted-org", runnerList.Entries[0].Name)
|
||||
assert.Equal(t, int64(34347), runnerList.Entries[0].ID)
|
||||
assert.False(t, runnerList.Entries[0].Ephemeral)
|
||||
assert.Len(t, runnerList.Entries[0].Labels, 2)
|
||||
assert.Equal(t, "runner_to_be_deleted", runnerList.Entries[0].Labels[0].Name)
|
||||
assert.Equal(t, "linux", runnerList.Entries[0].Labels[1].Name)
|
||||
idx := slices.IndexFunc(runnerList.Entries, func(e *api.ActionRunner) bool { return e.ID == 34347 })
|
||||
require.NotEqual(t, -1, idx)
|
||||
expectedRunner := runnerList.Entries[idx]
|
||||
|
||||
require.NotNil(t, expectedRunner)
|
||||
assert.Equal(t, "runner_to_be_deleted-org", expectedRunner.Name)
|
||||
assert.Equal(t, int64(34347), expectedRunner.ID)
|
||||
assert.False(t, expectedRunner.Ephemeral)
|
||||
assert.Len(t, expectedRunner.Labels, 2)
|
||||
assert.Equal(t, "runner_to_be_deleted", expectedRunner.Labels[0].Name)
|
||||
assert.Equal(t, "linux", expectedRunner.Labels[1].Name)
|
||||
|
||||
// Verify get the runner by id
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/orgs/org3/actions/runners/%d", runnerList.Entries[0].ID)).AddTokenAuth(token)
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/orgs/org3/actions/runners/%d", expectedRunner.ID)).AddTokenAuth(token)
|
||||
runnerResp := MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
runner := api.ActionRunner{}
|
||||
@ -183,11 +185,11 @@ func testActionsRunnerOwner(t *testing.T) {
|
||||
assert.Equal(t, "linux", runner.Labels[1].Name)
|
||||
|
||||
// Verify delete the runner by id
|
||||
req = NewRequest(t, "DELETE", fmt.Sprintf("/api/v1/orgs/org3/actions/runners/%d", runnerList.Entries[0].ID)).AddTokenAuth(token)
|
||||
req = NewRequest(t, "DELETE", fmt.Sprintf("/api/v1/orgs/org3/actions/runners/%d", expectedRunner.ID)).AddTokenAuth(token)
|
||||
MakeRequest(t, req, http.StatusNoContent)
|
||||
|
||||
// Verify runner deletion
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/orgs/org3/actions/runners/%d", runnerList.Entries[0].ID)).AddTokenAuth(token)
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/orgs/org3/actions/runners/%d", expectedRunner.ID)).AddTokenAuth(token)
|
||||
MakeRequest(t, req, http.StatusNotFound)
|
||||
})
|
||||
|
||||
|
79
tests/integration/ephemeral_actions_runner_deletion_test.go
Normal file
79
tests/integration/ephemeral_actions_runner_deletion_test.go
Normal file
@ -0,0 +1,79 @@
|
||||
// Copyright 2025 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package integration
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
actions_model "code.gitea.io/gitea/models/actions"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
repo_service "code.gitea.io/gitea/services/repository"
|
||||
user_service "code.gitea.io/gitea/services/user"
|
||||
"code.gitea.io/gitea/tests"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestEphemeralActionsRunnerDeletion(t *testing.T) {
|
||||
t.Run("ByTaskCompletion", testEphemeralActionsRunnerDeletionByTaskCompletion)
|
||||
t.Run("ByRepository", testEphemeralActionsRunnerDeletionByRepository)
|
||||
t.Run("ByUser", testEphemeralActionsRunnerDeletionByUser)
|
||||
}
|
||||
|
||||
// Test that the ephemeral runner is deleted when the task is finished
|
||||
func testEphemeralActionsRunnerDeletionByTaskCompletion(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
_, err := actions_model.GetRunnerByID(t.Context(), 34350)
|
||||
assert.NoError(t, err)
|
||||
|
||||
task := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionTask{ID: 52})
|
||||
assert.Equal(t, actions_model.StatusRunning, task.Status)
|
||||
|
||||
task.Status = actions_model.StatusSuccess
|
||||
err = actions_model.UpdateTask(t.Context(), task, "status")
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = actions_model.GetRunnerByID(t.Context(), 34350)
|
||||
assert.ErrorIs(t, err, util.ErrNotExist)
|
||||
}
|
||||
|
||||
func testEphemeralActionsRunnerDeletionByRepository(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
_, err := actions_model.GetRunnerByID(t.Context(), 34350)
|
||||
assert.NoError(t, err)
|
||||
|
||||
task := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionTask{ID: 52})
|
||||
assert.Equal(t, actions_model.StatusRunning, task.Status)
|
||||
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
|
||||
err = repo_service.DeleteRepositoryDirectly(t.Context(), user, task.RepoID, true)
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = actions_model.GetRunnerByID(t.Context(), 34350)
|
||||
assert.ErrorIs(t, err, util.ErrNotExist)
|
||||
}
|
||||
|
||||
// Test that the ephemeral runner is deleted when a user is deleted
|
||||
func testEphemeralActionsRunnerDeletionByUser(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
_, err := actions_model.GetRunnerByID(t.Context(), 34350)
|
||||
assert.NoError(t, err)
|
||||
|
||||
task := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionTask{ID: 52})
|
||||
assert.Equal(t, actions_model.StatusRunning, task.Status)
|
||||
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
|
||||
err = user_service.DeleteUser(t.Context(), user, true)
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = actions_model.GetRunnerByID(t.Context(), 34350)
|
||||
assert.ErrorIs(t, err, util.ErrNotExist)
|
||||
}
|
Reference in New Issue
Block a user