2024-09-10 20:14:47 +02:00
|
|
|
package schema
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2025-07-26 12:24:41 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2024-09-10 20:14:47 +02:00
|
|
|
"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)
|
|
|
|
}
|
2025-07-26 12:24:41 +00:00
|
|
|
|
|
|
|
func TestWorkflowCallRunsOn(t *testing.T) {
|
|
|
|
var node yaml.Node
|
|
|
|
err := yaml.Unmarshal([]byte(`
|
|
|
|
name: Build Silo Frontend DEV
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- dev
|
|
|
|
- dev-*
|
|
|
|
jobs:
|
|
|
|
build_frontend_dev:
|
|
|
|
name: Build Silo Frontend DEV
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
container:
|
|
|
|
image: code.forgejo.org/oci/node:22-bookworm
|
|
|
|
uses: ./.github/workflows/build.yaml
|
|
|
|
with:
|
|
|
|
STAGE: dev
|
|
|
|
secrets:
|
|
|
|
PACKAGE_WRITER_TOKEN: ${{ secrets.PACKAGE_WRITER_TOKEN }}
|
|
|
|
`), &node)
|
|
|
|
require.NoError(t, err)
|
|
|
|
n := &Node{
|
|
|
|
Definition: "workflow-root",
|
|
|
|
Schema: GetWorkflowSchema(),
|
|
|
|
}
|
|
|
|
require.NoError(t, n.UnmarshalYAML(&node))
|
|
|
|
}
|