@@ -9,9 +9,12 @@ import (
99 "testing"
1010
1111 auth_model "code.gitea.io/gitea/models/auth"
12+ "code.gitea.io/gitea/models/db"
1213 api "code.gitea.io/gitea/modules/structs"
1314 "code.gitea.io/gitea/tests"
1415
16+ actions_model "code.gitea.io/gitea/models/actions"
17+
1518 "github.com/stretchr/testify/assert"
1619)
1720
@@ -120,3 +123,35 @@ func TestAPIRunnerDeleteAdminRunnerNotFoundOrgApi(t *testing.T) {
120123 req := NewRequest (t , "DELETE" , fmt .Sprintf ("/api/v1/orgs/org3/actions/runners/%d" , 34344 )).AddTokenAuth (token )
121124 MakeRequest (t , req , http .StatusNotFound )
122125}
126+
127+ func TestAPIRunnerDeleteConflictWhileJobIsRunningOrgApi (t * testing.T ) {
128+ defer tests .PrepareTestEnv (t )()
129+ userUsername := "user2"
130+ token := getUserToken (t , userUsername , auth_model .AccessTokenScopeWriteOrganization )
131+
132+ _ , err := db .GetEngine (t .Context ()).Insert (& actions_model.ActionTask {
133+ RunnerID : 34347 ,
134+ Status : actions_model .StatusRunning ,
135+ })
136+ assert .NoError (t , err )
137+
138+ // Verify delete the runner by id is blocked by active job
139+ req := NewRequest (t , "DELETE" , fmt .Sprintf ("/api/v1/orgs/org3/actions/runners/%d" , 34347 )).AddTokenAuth (token )
140+ MakeRequest (t , req , http .StatusConflict )
141+ }
142+
143+ func TestAPIRunnerDeleteNoConflictWhileJobIsDoneOrgApi (t * testing.T ) {
144+ defer tests .PrepareTestEnv (t )()
145+ userUsername := "user2"
146+ token := getUserToken (t , userUsername , auth_model .AccessTokenScopeWriteOrganization )
147+
148+ _ , err := db .GetEngine (t .Context ()).Insert (& actions_model.ActionTask {
149+ RunnerID : 34347 ,
150+ Status : actions_model .StatusSuccess ,
151+ })
152+ assert .NoError (t , err )
153+
154+ // Verify delete the runner by id is ok
155+ req := NewRequest (t , "DELETE" , fmt .Sprintf ("/api/v1/orgs/org3/actions/runners/%d" , 34347 )).AddTokenAuth (token )
156+ MakeRequest (t , req , http .StatusNoContent )
157+ }
0 commit comments