@@ -317,6 +317,93 @@ func Test_statusValidator_listStatues(t *testing.T) {
317
317
want []* ghaStatus
318
318
}
319
319
tests := map [string ]test {
320
+ "succeeds to get job statuses even if the same job exists" : func () test {
321
+ c := & mock.Client {
322
+ GetCombinedStatusFunc : func (ctx context.Context , owner , repo , ref string , opts * github.ListOptions ) (* github.CombinedStatus , * github.Response , error ) {
323
+ return & github.CombinedStatus {
324
+ Statuses : []* github.RepoStatus {
325
+ // The first element here is the latest state.
326
+ {
327
+ Context : stringPtr ("job-01" ),
328
+ State : stringPtr (successState ),
329
+ },
330
+ {
331
+ Context : stringPtr ("job-01" ), // Same as above job name, and thus should be disregarded as old job status.
332
+ State : stringPtr (errorState ),
333
+ },
334
+ },
335
+ }, nil , nil
336
+ },
337
+ ListCheckRunsForRefFunc : func (ctx context.Context , owner , repo , ref string , opts * github.ListCheckRunsOptions ) (* github.ListCheckRunsResults , * github.Response , error ) {
338
+ return & github.ListCheckRunsResults {
339
+ CheckRuns : []* github.CheckRun {
340
+ // The first element here is the latest state.
341
+ {
342
+ Name : stringPtr ("job-02" ),
343
+ Status : stringPtr ("failure" ),
344
+ },
345
+ {
346
+ Name : stringPtr ("job-02" ), // Same as above job name, and thus should be disregarded as old job status.
347
+ Status : stringPtr (checkRunCompletedStatus ),
348
+ Conclusion : stringPtr (checkRunNeutralConclusion ),
349
+ },
350
+ {
351
+ Name : stringPtr ("job-03" ),
352
+ Status : stringPtr (checkRunCompletedStatus ),
353
+ Conclusion : stringPtr (checkRunNeutralConclusion ),
354
+ },
355
+ {
356
+ Name : stringPtr ("job-04" ),
357
+ Status : stringPtr (checkRunCompletedStatus ),
358
+ Conclusion : stringPtr (checkRunSuccessConclusion ),
359
+ },
360
+ {
361
+ Name : stringPtr ("job-05" ),
362
+ Status : stringPtr (checkRunCompletedStatus ),
363
+ Conclusion : stringPtr ("failure" ),
364
+ },
365
+ {
366
+ Name : stringPtr ("job-06" ),
367
+ Status : stringPtr (checkRunCompletedStatus ),
368
+ Conclusion : stringPtr (checkRunSkipConclusion ),
369
+ },
370
+ },
371
+ }, nil , nil
372
+ },
373
+ }
374
+ return test {
375
+ fields : fields {
376
+ client : c ,
377
+ selfJobName : "self-job" ,
378
+ owner : "test-owner" ,
379
+ repo : "test-repo" ,
380
+ ref : "main" ,
381
+ },
382
+ wantErr : false ,
383
+ want : []* ghaStatus {
384
+ {
385
+ Job : "job-01" ,
386
+ State : successState ,
387
+ },
388
+ {
389
+ Job : "job-02" ,
390
+ State : pendingState ,
391
+ },
392
+ {
393
+ Job : "job-03" ,
394
+ State : successState ,
395
+ },
396
+ {
397
+ Job : "job-04" ,
398
+ State : successState ,
399
+ },
400
+ {
401
+ Job : "job-05" ,
402
+ State : errorState ,
403
+ },
404
+ },
405
+ }
406
+ }(),
320
407
"returns error when the GetCombinedStatus returns an error" : func () test {
321
408
c := & mock.Client {
322
409
GetCombinedStatusFunc : func (ctx context.Context , owner , repo , ref string , opts * github.ListOptions ) (* github.CombinedStatus , * github.Response , error ) {
0 commit comments