1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-08-06 17:40:58 +00:00
forgejo-runner/act/schema/schema_test.go
Earl Warren 34939ad5f4 fix: allow using the env context in actions defaults (#204)
Reviewed-on: https://code.forgejo.org/forgejo/act/pulls/204
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
Co-authored-by: Earl Warren <contact@earl-warren.org>
Co-committed-by: Earl Warren <contact@earl-warren.org>
2025-07-27 15:24:49 +00:00

151 lines
3.2 KiB
Go

package schema
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"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)
}
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))
}
func TestActionSchema(t *testing.T) {
var node yaml.Node
err := yaml.Unmarshal([]byte(`
name: 'action name'
author: 'action authors'
description: |
action description
inputs:
url:
description: 'url description'
default: '${{ env.GITHUB_SERVER_URL }}'
repo:
description: 'repo description'
default: '${{ github.repository }}'
runs:
using: "composite"
steps:
- run: echo "${{ github.action_path }}"
`), &node)
if !assert.NoError(t, err) {
return
}
err = (&Node{
Definition: "action-root",
Schema: GetActionSchema(),
}).UnmarshalYAML(&node)
assert.NoError(t, err)
}