@@ -470,6 +470,53 @@ func createJob(t *testing.T, input string, result string) *model.Job {
470470 return job
471471}
472472
473+ func TestRunContextRunsOnPlatformNames (t * testing.T ) {
474+ log .SetLevel (log .DebugLevel )
475+ assertObject := assert .New (t )
476+
477+ rc := createIfTestRunContext (map [string ]* model.Job {
478+ "job1" : createJob (t , `runs-on: ubuntu-latest` , "" ),
479+ })
480+ assertObject .Equal ([]string {"ubuntu-latest" }, rc .runsOnPlatformNames (context .Background ()))
481+
482+ rc = createIfTestRunContext (map [string ]* model.Job {
483+ "job1" : createJob (t , `runs-on: ${{ 'ubuntu-latest' }}` , "" ),
484+ })
485+ assertObject .Equal ([]string {"ubuntu-latest" }, rc .runsOnPlatformNames (context .Background ()))
486+
487+ rc = createIfTestRunContext (map [string ]* model.Job {
488+ "job1" : createJob (t , `runs-on: [self-hosted, my-runner]` , "" ),
489+ })
490+ assertObject .Equal ([]string {"self-hosted" , "my-runner" }, rc .runsOnPlatformNames (context .Background ()))
491+
492+ rc = createIfTestRunContext (map [string ]* model.Job {
493+ "job1" : createJob (t , `runs-on: [self-hosted, "${{ 'my-runner' }}"]` , "" ),
494+ })
495+ assertObject .Equal ([]string {"self-hosted" , "my-runner" }, rc .runsOnPlatformNames (context .Background ()))
496+
497+ rc = createIfTestRunContext (map [string ]* model.Job {
498+ "job1" : createJob (t , `runs-on: ${{ fromJSON('["ubuntu-latest"]') }}` , "" ),
499+ })
500+ assertObject .Equal ([]string {"ubuntu-latest" }, rc .runsOnPlatformNames (context .Background ()))
501+
502+ // test missing / invalid runs-on
503+ rc = createIfTestRunContext (map [string ]* model.Job {
504+ "job1" : createJob (t , `name: something` , "" ),
505+ })
506+ assertObject .Equal ([]string {}, rc .runsOnPlatformNames (context .Background ()))
507+
508+ rc = createIfTestRunContext (map [string ]* model.Job {
509+ "job1" : createJob (t , `runs-on:
510+ mapping: value` , "" ),
511+ })
512+ assertObject .Equal ([]string {}, rc .runsOnPlatformNames (context .Background ()))
513+
514+ rc = createIfTestRunContext (map [string ]* model.Job {
515+ "job1" : createJob (t , `runs-on: ${{ invalid expression }}` , "" ),
516+ })
517+ assertObject .Equal ([]string {}, rc .runsOnPlatformNames (context .Background ()))
518+ }
519+
473520func TestRunContextIsEnabled (t * testing.T ) {
474521 log .SetLevel (log .DebugLevel )
475522 assertObject := assert .New (t )
0 commit comments