Skip to content

Commit 2a5c4a6

Browse files
committed
feat: Update the unittests
1 parent cb2fc05 commit 2a5c4a6

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

modules/structs/repo_actions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,5 +209,5 @@ type ActionRunnersResponse struct {
209209

210210
// UpdateRunnerCapacityOption options for updating runner capacity
211211
type UpdateRunnerCapacityOption struct {
212-
Capacity int `json:"capacity" binding:"Required"`
212+
Capacity int `json:"capacity" binding:"Min(0)"`
213213
}

tests/integration/api_runner_capacity_test.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,41 @@ import (
1010
"testing"
1111

1212
actions_model "code.gitea.io/gitea/models/actions"
13+
auth_model "code.gitea.io/gitea/models/auth"
14+
"code.gitea.io/gitea/models/db"
1315
"code.gitea.io/gitea/models/unittest"
1416
api "code.gitea.io/gitea/modules/structs"
1517
"code.gitea.io/gitea/tests"
1618

1719
"github.com/stretchr/testify/assert"
20+
"github.com/stretchr/testify/require"
1821
)
1922

2023
func TestAPIUpdateRunnerCapacity(t *testing.T) {
2124
defer tests.PrepareTestEnv(t)()
2225

26+
ctx := context.Background()
27+
28+
// Clean up existing runners
29+
require.NoError(t, db.DeleteAllRecords("action_runner"))
30+
2331
// Create a test runner
2432
runner := &actions_model.ActionRunner{
25-
UUID: "test-capacity-runner",
26-
Name: "Test Capacity Runner",
27-
OwnerID: 0,
28-
RepoID: 0,
29-
Capacity: 1,
33+
UUID: "test-capacity-runner",
34+
Name: "Test Capacity Runner",
35+
OwnerID: 0,
36+
RepoID: 0,
37+
Capacity: 1,
38+
TokenHash: "test-capacity-hash",
39+
Token: "test-capacity-token",
3040
}
31-
unittest.AssertExistsAndLoadBean(t, runner)
41+
require.NoError(t, actions_model.CreateRunner(ctx, runner))
42+
43+
// Load the created runner to get the ID
44+
runner = unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRunner{UUID: "test-capacity-runner"})
3245

3346
session := loginUser(t, "user1")
34-
token := getTokenForLoggedInUser(t, session)
47+
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteAdmin)
3548

3649
t.Run("UpdateCapacity", func(t *testing.T) {
3750
req := NewRequestWithJSON(t, "PATCH",

0 commit comments

Comments
 (0)