-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
1 parent
d8b6f61
commit 4143017
Showing
2 changed files
with
117 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |