mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-03-22 06:45:03 +01:00
feat: implement case function (#16)
Follow GitHub Actions * added unit tests Closes #15 Reviewed-on: https://gitea.com/actions-oss/act-cli/pulls/16 Co-authored-by: ChristopherHX <christopher.homberger@web.de> Co-committed-by: ChristopherHX <christopher.homberger@web.de>
This commit is contained in:
committed by
ChristopherHX
parent
83cbf1f2b8
commit
ee2e0135d5
@@ -148,3 +148,78 @@ jobs:
|
||||
}).UnmarshalYAML(&node)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestSchemaErrors(t *testing.T) {
|
||||
table := []struct {
|
||||
name string // test name
|
||||
input string // workflow yaml input
|
||||
err string // error message substring
|
||||
}{
|
||||
{
|
||||
name: "case even parameters is error",
|
||||
input: `
|
||||
${{ 'on' }}: push
|
||||
jobs:
|
||||
job-with-condition:
|
||||
runs-on: self-hosted
|
||||
steps:
|
||||
- run: echo ${{ case(1 == 1, 'zero', 2 == 2, 'one', 'two', '') }}
|
||||
`,
|
||||
err: "expected odd number of parameters for case got 6",
|
||||
},
|
||||
{
|
||||
name: "case odd parameters no error",
|
||||
input: `
|
||||
${{ 'on' }}: push
|
||||
jobs:
|
||||
job-with-condition:
|
||||
runs-on: self-hosted
|
||||
steps:
|
||||
- run: echo ${{ case(1 == 1, 'zero', 2 == 2, 'one', 'two') }}
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "case 1 parameters error",
|
||||
input: `
|
||||
${{ 'on' }}: push
|
||||
jobs:
|
||||
job-with-condition:
|
||||
runs-on: self-hosted
|
||||
steps:
|
||||
- run: echo ${{ case(1 == 1) }}
|
||||
`,
|
||||
err: "missing parameters for case expected >= 3 got 1",
|
||||
},
|
||||
{
|
||||
name: "invalid expression in step uses",
|
||||
input: `
|
||||
on: push
|
||||
jobs:
|
||||
job-with-condition:
|
||||
runs-on: self-hosted
|
||||
steps:
|
||||
- uses: ${{ format('actions/checkout@v%s', 'v2') }}
|
||||
`,
|
||||
err: "Line: 7 Column 17: expressions are not allowed here",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range table {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
var node yaml.Node
|
||||
err := yaml.Unmarshal([]byte(test.input), &node)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
err = (&Node{
|
||||
Definition: "workflow-root-strict",
|
||||
Schema: GetWorkflowSchema(),
|
||||
}).UnmarshalYAML(&node)
|
||||
if test.err != "" {
|
||||
assert.ErrorContains(t, err, test.err)
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user