mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-09-15 18:57:01 +00:00
fix: schema validation for job if functions (#2446)
* fix: schema validation for job if functions * Add Tests * Update pkg/schema/schema.go Co-authored-by: Josh Soref <2119212+jsoref@users.noreply.github.com> * Update pkg/schema/schema.go --------- Co-authored-by: Josh Soref <2119212+jsoref@users.noreply.github.com> (cherry picked from commit f043eb7079a16dfcf54d1f44fe66795ff76e973a)
This commit is contained in:
parent
65ae238f17
commit
e489be545d
2 changed files with 117 additions and 7 deletions
92
act/schema/schema_test.go
Normal file
92
act/schema/schema_test.go
Normal file
|
@ -0,0 +1,92 @@
|
|||
package schema
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
func TestAdditionalFunctions(t *testing.T) {
|
||||
var node yaml.Node
|
||||
err := yaml.Unmarshal([]byte(`
|
||||
on: push
|
||||
jobs:
|
||||
job-with-condition:
|
||||
runs-on: self-hosted
|
||||
if: success() || success('joba', 'jobb') || failure() || failure('joba', 'jobb') || always() || cancelled()
|
||||
steps:
|
||||
- run: exit 0
|
||||
`), &node)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
err = (&Node{
|
||||
Definition: "workflow-root-strict",
|
||||
Schema: GetWorkflowSchema(),
|
||||
}).UnmarshalYAML(&node)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestAdditionalFunctionsFailure(t *testing.T) {
|
||||
var node yaml.Node
|
||||
err := yaml.Unmarshal([]byte(`
|
||||
on: push
|
||||
jobs:
|
||||
job-with-condition:
|
||||
runs-on: self-hosted
|
||||
if: success() || success('joba', 'jobb') || failure() || failure('joba', 'jobb') || always('error')
|
||||
steps:
|
||||
- run: exit 0
|
||||
`), &node)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
err = (&Node{
|
||||
Definition: "workflow-root-strict",
|
||||
Schema: GetWorkflowSchema(),
|
||||
}).UnmarshalYAML(&node)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestAdditionalFunctionsSteps(t *testing.T) {
|
||||
var node yaml.Node
|
||||
err := yaml.Unmarshal([]byte(`
|
||||
on: push
|
||||
jobs:
|
||||
job-with-condition:
|
||||
runs-on: self-hosted
|
||||
steps:
|
||||
- run: exit 0
|
||||
if: success() || failure() || always()
|
||||
`), &node)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
err = (&Node{
|
||||
Definition: "workflow-root-strict",
|
||||
Schema: GetWorkflowSchema(),
|
||||
}).UnmarshalYAML(&node)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestAdditionalFunctionsStepsExprSyntax(t *testing.T) {
|
||||
var node yaml.Node
|
||||
err := yaml.Unmarshal([]byte(`
|
||||
on: push
|
||||
jobs:
|
||||
job-with-condition:
|
||||
runs-on: self-hosted
|
||||
steps:
|
||||
- run: exit 0
|
||||
if: ${{ success() || failure() || always() }}
|
||||
`), &node)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
err = (&Node{
|
||||
Definition: "workflow-root-strict",
|
||||
Schema: GetWorkflowSchema(),
|
||||
}).UnmarshalYAML(&node)
|
||||
assert.NoError(t, err)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue