@@ -1120,51 +1120,51 @@ func Test_WebhookWorkflowRun(t *testing.T) {
11201120 defer provider .Close ()
11211121 webhookData .URL = provider .URL ()
11221122
1123- tests := []struct {
1123+ testCases := []struct {
11241124 name string
1125- callback func (t * testing.T , webhookData * workflowRunWebhook )
1125+ testFunc func (t * testing.T , webhookData * workflowRunWebhook )
11261126 }{
11271127 {
11281128 name : "WorkflowRun" ,
1129- callback : testWebhookWorkflowRun ,
1129+ testFunc : testWebhookWorkflowRun ,
11301130 },
11311131 {
11321132 name : "WorkflowRunDepthLimit" ,
1133- callback : testWebhookWorkflowRunDepthLimit ,
1133+ testFunc : testWebhookWorkflowRunDepthLimit ,
11341134 },
11351135 {
1136- name : "WorkflowRunDuplicateEvents " ,
1137- callback : testWorkflowRunDuplicateEvents ,
1136+ name : "WorkflowRunEvents " ,
1137+ testFunc : testWorkflowRunEvents ,
11381138 },
11391139 {
1140- name : "WorkflowRunEventDuplicateEventsRerun " ,
1141- callback : testWorkflowRunDuplicateEventsRerun ,
1140+ name : "WorkflowRunEventsOnRerun " ,
1141+ testFunc : testWorkflowRunEventsOnRerun ,
11421142 },
11431143 {
1144- name : "WorkflowRunDuplicateEventsCancelAbandoned " ,
1145- callback : func (t * testing.T , webhookData * workflowRunWebhook ) {
1146- testWorkflowRunDuplicateEventsCancelAbandoned (t , webhookData , true )
1144+ name : "WorkflowRunEventsOnCancellingAllJobsAbandonedRun " ,
1145+ testFunc : func (t * testing.T , webhookData * workflowRunWebhook ) {
1146+ testWorkflowRunEventsOnCancellingAbandonedRun (t , webhookData , true )
11471147 },
11481148 },
11491149 {
1150- name : "WorkflowRunDuplicateEventsCancelAbandoned " ,
1151- callback : func (t * testing.T , webhookData * workflowRunWebhook ) {
1152- testWorkflowRunDuplicateEventsCancelAbandoned (t , webhookData , false )
1150+ name : "WorkflowRunEventsOnCancellingPartiallyAbandonedRun " ,
1151+ testFunc : func (t * testing.T , webhookData * workflowRunWebhook ) {
1152+ testWorkflowRunEventsOnCancellingAbandonedRun (t , webhookData , false )
11531153 },
11541154 },
11551155 }
1156- for _ , test := range tests {
1157- t .Run (test .name , func (t * testing.T ) {
1156+ for _ , obj := range testCases {
1157+ t .Run (obj .name , func (t * testing.T ) {
11581158 webhookData .payloads = nil
11591159 webhookData .triggeredEvent = ""
11601160 onGiteaRun (t , func (t * testing.T , giteaURL * url.URL ) {
1161- test . callback (t , webhookData )
1161+ obj . testFunc (t , webhookData )
11621162 })
11631163 })
11641164 }
11651165}
11661166
1167- func testWorkflowRunDuplicateEvents (t * testing.T , webhookData * workflowRunWebhook ) {
1167+ func testWorkflowRunEvents (t * testing.T , webhookData * workflowRunWebhook ) {
11681168 // 1. create a new webhook with special webhook for repo1
11691169 user2 := unittest .AssertExistsAndLoadBean (t , & user_model.User {ID : 2 })
11701170 session := loginUser (t , "user2" )
@@ -1187,64 +1187,64 @@ func testWorkflowRunDuplicateEvents(t *testing.T, webhookData *workflowRunWebhoo
11871187 workflow_dispatch:
11881188
11891189jobs:
1190- test:
1190+ test:
11911191 runs-on: ubuntu-latest
11921192 steps:
11931193 - run: exit 0
11941194
1195- test2:
1195+ test2:
11961196 needs: [test]
11971197 runs-on: ubuntu-latest
11981198 steps:
11991199 - run: exit 0
12001200
1201- test3:
1201+ test3:
12021202 needs: [test, test2]
12031203 runs-on: ubuntu-latest
12041204 steps:
12051205 - run: exit 0
1206-
1207- test4:
1206+
1207+ test4:
12081208 needs: [test, test2, test3]
12091209 runs-on: ubuntu-latest
12101210 steps:
12111211 - run: exit 0
1212-
1213- test5:
1212+
1213+ test5:
12141214 needs: [test, test2, test4]
12151215 runs-on: ubuntu-latest
12161216 steps:
12171217 - run: exit 0
1218-
1218+
12191219 test6:
12201220 strategy:
12211221 matrix:
1222- os: [ubuntu-20.04, ubuntu-22.04, ubuntu-24.04]
1222+ os: [ubuntu-20.04, ubuntu-22.04, ubuntu-24.04]
12231223 needs: [test, test2, test3]
12241224 runs-on: ${{ matrix.os }}
12251225 steps:
12261226 - run: exit 0
1227-
1228- test7:
1227+
1228+ test7:
12291229 needs: test6
12301230 runs-on: ubuntu-latest
12311231 steps:
12321232 - run: exit 0
1233-
1234- test8:
1233+
1234+ test8:
12351235 runs-on: ubuntu-latest
12361236 steps:
12371237 - run: exit 0
1238-
1239- test9:
1238+
1239+ test9:
12401240 strategy:
12411241 matrix:
12421242 os: [ubuntu-20.04, ubuntu-22.04, ubuntu-24.04, ubuntu-25.04, windows-2022, windows-2025, macos-13, macos-14, macos-15]
12431243 runs-on: ${{ matrix.os }}
12441244 steps:
12451245 - run: exit 0
12461246
1247- test10:
1247+ test10:
12481248 runs-on: ubuntu-latest
12491249 steps:
12501250 - run: exit 0`
@@ -1285,7 +1285,7 @@ jobs:
12851285 assert .Equal (t , "user2/repo1" , webhookData .payloads [1 ].Repo .FullName )
12861286}
12871287
1288- func testWorkflowRunDuplicateEventsRerun (t * testing.T , webhookData * workflowRunWebhook ) {
1288+ func testWorkflowRunEventsOnRerun (t * testing.T , webhookData * workflowRunWebhook ) {
12891289 // 1. create a new webhook with special webhook for repo1
12901290 user2 := unittest .AssertExistsAndLoadBean (t , & user_model.User {ID : 2 })
12911291 session := loginUser (t , "user2" )
@@ -1314,64 +1314,64 @@ func testWorkflowRunDuplicateEventsRerun(t *testing.T, webhookData *workflowRunW
13141314 workflow_dispatch:
13151315
13161316jobs:
1317- test:
1317+ test:
13181318 runs-on: ubuntu-latest
13191319 steps:
13201320 - run: exit 0
13211321
1322- test2:
1322+ test2:
13231323 needs: [test]
13241324 runs-on: ubuntu-latest
13251325 steps:
13261326 - run: exit 0
13271327
1328- test3:
1328+ test3:
13291329 needs: [test, test2]
13301330 runs-on: ubuntu-latest
13311331 steps:
13321332 - run: exit 0
1333-
1334- test4:
1333+
1334+ test4:
13351335 needs: [test, test2, test3]
13361336 runs-on: ubuntu-latest
13371337 steps:
13381338 - run: exit 0
1339-
1340- test5:
1339+
1340+ test5:
13411341 needs: [test, test2, test4]
13421342 runs-on: ubuntu-latest
13431343 steps:
13441344 - run: exit 0
1345-
1345+
13461346 test6:
13471347 strategy:
13481348 matrix:
1349- os: [ubuntu-20.04, ubuntu-22.04, ubuntu-24.04]
1349+ os: [ubuntu-20.04, ubuntu-22.04, ubuntu-24.04]
13501350 needs: [test, test2, test3]
13511351 runs-on: ${{ matrix.os }}
13521352 steps:
13531353 - run: exit 0
1354-
1355- test7:
1354+
1355+ test7:
13561356 needs: test6
13571357 runs-on: ubuntu-latest
13581358 steps:
13591359 - run: exit 0
1360-
1361- test8:
1360+
1361+ test8:
13621362 runs-on: ubuntu-latest
13631363 steps:
13641364 - run: exit 0
1365-
1366- test9:
1365+
1366+ test9:
13671367 strategy:
13681368 matrix:
13691369 os: [ubuntu-20.04, ubuntu-22.04, ubuntu-24.04, ubuntu-25.04, windows-2022, windows-2025, macos-13, macos-14, macos-15]
13701370 runs-on: ${{ matrix.os }}
13711371 steps:
13721372 - run: exit 0
13731373
1374- test10:
1374+ test10:
13751375 runs-on: ubuntu-latest
13761376 steps:
13771377 - run: exit 0`
@@ -1391,10 +1391,9 @@ jobs:
13911391 assert .Equal (t , "repo1" , webhookData .payloads [0 ].Repo .Name )
13921392 assert .Equal (t , "user2/repo1" , webhookData .payloads [0 ].Repo .FullName )
13931393
1394- tasks := make ([]* runnerv1.Task , len (runners ))
1395- for i := range runners {
1396- tasks [i ] = runners [i ].fetchTask (t )
1397- runners [i ].execTask (t , tasks [i ], & mockTaskOutcome {
1394+ for _ , runner := range runners {
1395+ task := runner .fetchTask (t )
1396+ runner .execTask (t , task , & mockTaskOutcome {
13981397 result : runnerv1 .Result_RESULT_SUCCESS ,
13991398 })
14001399 }
@@ -1430,7 +1429,9 @@ jobs:
14301429 assert .Len (t , webhookData .payloads , 3 )
14311430}
14321431
1433- func testWorkflowRunDuplicateEventsCancelAbandoned (t * testing.T , webhookData * workflowRunWebhook , partiallyAbandoned bool ) {
1432+ func testWorkflowRunEventsOnCancellingAbandonedRun (t * testing.T , webhookData * workflowRunWebhook , allJobsAbandoned bool ) {
1433+ defer test .MockVariableValue (& setting .Actions .AbandonedJobTimeout , (time .Duration )(0 ))()
1434+
14341435 // 1. create a new webhook with special webhook for repo1
14351436 user2 := unittest .AssertExistsAndLoadBean (t , & user_model.User {ID : 2 })
14361437 session := loginUser (t , "user2" )
@@ -1459,64 +1460,64 @@ func testWorkflowRunDuplicateEventsCancelAbandoned(t *testing.T, webhookData *wo
14591460 workflow_dispatch:
14601461
14611462jobs:
1462- test:
1463+ test:
14631464 runs-on: ubuntu-latest
14641465 steps:
14651466 - run: exit 0
14661467
1467- test2:
1468+ test2:
14681469 needs: [test]
14691470 runs-on: ubuntu-latest
14701471 steps:
14711472 - run: exit 0
14721473
1473- test3:
1474+ test3:
14741475 needs: [test, test2]
14751476 runs-on: ubuntu-latest
14761477 steps:
14771478 - run: exit 0
1478-
1479- test4:
1479+
1480+ test4:
14801481 needs: [test, test2, test3]
14811482 runs-on: ubuntu-latest
14821483 steps:
14831484 - run: exit 0
1484-
1485- test5:
1485+
1486+ test5:
14861487 needs: [test, test2, test4]
14871488 runs-on: ubuntu-latest
14881489 steps:
14891490 - run: exit 0
1490-
1491+
14911492 test6:
14921493 strategy:
14931494 matrix:
1494- os: [ubuntu-20.04, ubuntu-22.04, ubuntu-24.04]
1495+ os: [ubuntu-20.04, ubuntu-22.04, ubuntu-24.04]
14951496 needs: [test, test2, test3]
14961497 runs-on: ${{ matrix.os }}
14971498 steps:
14981499 - run: exit 0
1499-
1500- test7:
1500+
1501+ test7:
15011502 needs: test6
15021503 runs-on: ubuntu-latest
15031504 steps:
15041505 - run: exit 0
1505-
1506- test8:
1506+
1507+ test8:
15071508 runs-on: ubuntu-latest
15081509 steps:
15091510 - run: exit 0
1510-
1511- test9:
1511+
1512+ test9:
15121513 strategy:
15131514 matrix:
15141515 os: [ubuntu-20.04, ubuntu-22.04, ubuntu-24.04, ubuntu-25.04, windows-2022, windows-2025, macos-13, macos-14, macos-15]
15151516 runs-on: ${{ matrix.os }}
15161517 steps:
15171518 - run: exit 0
15181519
1519- test10:
1520+ test10:
15201521 runs-on: ubuntu-latest
15211522 steps:
15221523 - run: exit 0`
@@ -1536,22 +1537,19 @@ jobs:
15361537 assert .Equal (t , "repo1" , webhookData .payloads [0 ].Repo .Name )
15371538 assert .Equal (t , "user2/repo1" , webhookData .payloads [0 ].Repo .FullName )
15381539
1539- tasks := make ([]* runnerv1.Task , len (runners ))
1540- for i := range runners {
1541- tasks [i ] = runners [i ].fetchTask (t )
1542- if ! partiallyAbandoned {
1543- runners [i ].execTask (t , tasks [i ], & mockTaskOutcome {
1540+ for _ , runner := range runners {
1541+ task := runner .fetchTask (t )
1542+ if ! allJobsAbandoned {
1543+ runner .execTask (t , task , & mockTaskOutcome {
15441544 result : runnerv1 .Result_RESULT_SUCCESS ,
15451545 })
15461546 }
15471547 }
15481548
1549- defer test .MockVariableValue (& setting .Actions .AbandonedJobTimeout , (time .Duration )(0 ))()
1550-
15511549 err = actions .CancelAbandonedJobs (t .Context ())
15521550 assert .NoError (t , err )
15531551
1554- if partiallyAbandoned {
1552+ if allJobsAbandoned {
15551553 assert .Len (t , webhookData .payloads , 1 )
15561554 } else {
15571555 assert .Len (t , webhookData .payloads , 2 )
0 commit comments