courgette/internal/workflow/models_test.go

80 lines
1.8 KiB
Go

package workflow
import (
"testing"
)
func TestWorkingDirectoryDefaultsToCurrentDirectory(t *testing.T) {
sample := `
jobs:
jobA:
runs-on: default
steps:
- run: echo "test"
`
workflow, _ := FromYamlBytes([]byte(sample))
workDir := workflow.GetWorkingDirectory("jobA", 0)
if workDir != "." {
t.Errorf("Expected current directory as working directory, got %s", workDir)
}
}
func TestWorkingDirectoryUsesStepDefault(t *testing.T) {
sample := `
jobs:
jobA:
runs-on: default
steps:
- run: echo "test"
working-directory: ./test
`
workflow, _ := FromYamlBytes([]byte(sample))
workDir := workflow.GetWorkingDirectory("jobA", 0)
if workDir != "./test" {
t.Errorf("Expected current directory as ./test working directory, got %s", workDir)
}
}
func TestWorkingDirectoryUsesJobDefaultsIfNoStepDefault(t *testing.T) {
sample := `
jobs:
jobA:
runs-on: default
defaults:
run:
working-directory: ./test-job
steps:
- run: echo "test"
`
workflow, _ := FromYamlBytes([]byte(sample))
workDir := workflow.GetWorkingDirectory("jobA", 0)
if workDir != "./test-job" {
t.Errorf("Expected current directory as ./test working directory, got %s", workDir)
}
}
func TestWorkingDirectoryFromStepOverridesJobDefault(t *testing.T) {
sample := `
jobs:
jobA:
runs-on: default
defaults:
run:
working-directory: ./test-job
steps:
- run: echo "test"
working-directory: ./test-step
`
workflow, _ := FromYamlBytes([]byte(sample))
workDir := workflow.GetWorkingDirectory("jobA", 0)
if workDir != "./test-step" {
t.Errorf("Expected current directory as ./test working directory, got %s", workDir)
}
}