diff options
author | Jason Song <i@wolfogre.com> | 2023-08-02 05:52:14 +0200 |
---|---|---|
committer | Jason Song <i@wolfogre.com> | 2023-08-02 05:52:14 +0200 |
commit | 22d91e3ac3740bb00e8ec044026f028f811cfb61 (patch) | |
tree | b70544ac0c3ed631bed69ac8b85030d841408a62 /pkg/model/workflow_test.go | |
parent | Support expression in `uses` (#75) (diff) | |
parent | chore: bump VERSION to 0.2.49 (diff) | |
download | forgejo-act-22d91e3ac3740bb00e8ec044026f028f811cfb61.tar.xz forgejo-act-22d91e3ac3740bb00e8ec044026f028f811cfb61.zip |
Merge tag 'nektos/v0.2.49'
Conflicts:
cmd/input.go
go.mod
go.sum
pkg/exprparser/interpreter.go
pkg/model/workflow.go
pkg/runner/expression.go
pkg/runner/job_executor.go
pkg/runner/runner.go
Diffstat (limited to 'pkg/model/workflow_test.go')
-rw-r--r-- | pkg/model/workflow_test.go | 81 |
1 files changed, 71 insertions, 10 deletions
diff --git a/pkg/model/workflow_test.go b/pkg/model/workflow_test.go index 3729add..8b33662 100644 --- a/pkg/model/workflow_test.go +++ b/pkg/model/workflow_test.go @@ -229,20 +229,81 @@ jobs: runs-on: ubuntu-latest steps: - run: echo - remote-reusable-workflow: - runs-on: ubuntu-latest - uses: remote/repo/.github/workflows/workflow.yml@main - local-reusable-workflow: - runs-on: ubuntu-latest - uses: ./.github/workflows/workflow.yml + remote-reusable-workflow-yml: + uses: remote/repo/some/path/to/workflow.yml@main + remote-reusable-workflow-yaml: + uses: remote/repo/some/path/to/workflow.yaml@main + remote-reusable-workflow-custom-path: + uses: remote/repo/path/to/workflow.yml@main + local-reusable-workflow-yml: + uses: ./some/path/to/workflow.yml + local-reusable-workflow-yaml: + uses: ./some/path/to/workflow.yaml +` + + workflow, err := ReadWorkflow(strings.NewReader(yaml)) + assert.NoError(t, err, "read workflow should succeed") + assert.Len(t, workflow.Jobs, 6) + + jobType, err := workflow.Jobs["default-job"].Type() + assert.Equal(t, nil, err) + assert.Equal(t, JobTypeDefault, jobType) + + jobType, err = workflow.Jobs["remote-reusable-workflow-yml"].Type() + assert.Equal(t, nil, err) + assert.Equal(t, JobTypeReusableWorkflowRemote, jobType) + + jobType, err = workflow.Jobs["remote-reusable-workflow-yaml"].Type() + assert.Equal(t, nil, err) + assert.Equal(t, JobTypeReusableWorkflowRemote, jobType) + + jobType, err = workflow.Jobs["remote-reusable-workflow-custom-path"].Type() + assert.Equal(t, nil, err) + assert.Equal(t, JobTypeReusableWorkflowRemote, jobType) + + jobType, err = workflow.Jobs["local-reusable-workflow-yml"].Type() + assert.Equal(t, nil, err) + assert.Equal(t, JobTypeReusableWorkflowLocal, jobType) + + jobType, err = workflow.Jobs["local-reusable-workflow-yaml"].Type() + assert.Equal(t, nil, err) + assert.Equal(t, JobTypeReusableWorkflowLocal, jobType) +} + +func TestReadWorkflow_JobTypes_InvalidPath(t *testing.T) { + yaml := ` +name: invalid job definition + +jobs: + remote-reusable-workflow-missing-version: + uses: remote/repo/some/path/to/workflow.yml + remote-reusable-workflow-bad-extension: + uses: remote/repo/some/path/to/workflow.json + local-reusable-workflow-bad-extension: + uses: ./some/path/to/workflow.json + local-reusable-workflow-bad-path: + uses: some/path/to/workflow.yaml ` workflow, err := ReadWorkflow(strings.NewReader(yaml)) assert.NoError(t, err, "read workflow should succeed") - assert.Len(t, workflow.Jobs, 3) - assert.Equal(t, workflow.Jobs["default-job"].Type(), JobTypeDefault) - assert.Equal(t, workflow.Jobs["remote-reusable-workflow"].Type(), JobTypeReusableWorkflowRemote) - assert.Equal(t, workflow.Jobs["local-reusable-workflow"].Type(), JobTypeReusableWorkflowLocal) + assert.Len(t, workflow.Jobs, 4) + + jobType, err := workflow.Jobs["remote-reusable-workflow-missing-version"].Type() + assert.Equal(t, JobTypeInvalid, jobType) + assert.NotEqual(t, nil, err) + + jobType, err = workflow.Jobs["remote-reusable-workflow-bad-extension"].Type() + assert.Equal(t, JobTypeInvalid, jobType) + assert.NotEqual(t, nil, err) + + jobType, err = workflow.Jobs["local-reusable-workflow-bad-extension"].Type() + assert.Equal(t, JobTypeInvalid, jobType) + assert.NotEqual(t, nil, err) + + jobType, err = workflow.Jobs["local-reusable-workflow-bad-path"].Type() + assert.Equal(t, JobTypeInvalid, jobType) + assert.NotEqual(t, nil, err) } func TestReadWorkflow_StepsTypes(t *testing.T) { |