···
7
+
"github.com/stretchr/testify/assert"
8
+
"tangled.sh/tangled.sh/core/api/tangled"
11
+
var trigger = tangled.Pipeline_TriggerMetadata{
12
+
Kind: TriggerKindPush,
13
+
Push: &tangled.Pipeline_PushTriggerData{
14
+
Ref: "refs/heads/main",
15
+
OldSha: strings.Repeat("0", 40),
16
+
NewSha: strings.Repeat("f", 40),
20
+
var when = []Constraint{
22
+
Event: []string{"push"},
23
+
Branch: []string{"main"},
27
+
func TestCompileWorkflow_MatchingWorkflowWithSteps(t *testing.T) {
29
+
Name: ".tangled/workflows/test.yml",
32
+
{Name: "Test", Command: "go test ./..."},
34
+
CloneOpts: CloneOpts{}, // default true
37
+
c := Compiler{Trigger: trigger}
38
+
cp := c.Compile([]Workflow{wf})
40
+
assert.Len(t, cp.Workflows, 1)
41
+
assert.Equal(t, wf.Name, cp.Workflows[0].Name)
42
+
assert.False(t, cp.Workflows[0].Clone.Skip)
43
+
assert.False(t, c.Diagnostics.IsErr())
46
+
func TestCompileWorkflow_EmptySteps(t *testing.T) {
48
+
Name: ".tangled/workflows/empty.yml",
50
+
Steps: []Step{}, // no steps
53
+
c := Compiler{Trigger: trigger}
54
+
cp := c.Compile([]Workflow{wf})
56
+
assert.Len(t, cp.Workflows, 0)
57
+
assert.Len(t, c.Diagnostics.Warnings, 1)
58
+
assert.Equal(t, WorkflowSkipped, c.Diagnostics.Warnings[0].Type)
61
+
func TestCompileWorkflow_TriggerMismatch(t *testing.T) {
63
+
Name: ".tangled/workflows/mismatch.yml",
66
+
Event: []string{"push"},
67
+
Branch: []string{"master"}, // different branch
71
+
{Name: "Lint", Command: "golint ./..."},
75
+
c := Compiler{Trigger: trigger}
76
+
cp := c.Compile([]Workflow{wf})
78
+
assert.Len(t, cp.Workflows, 0)
79
+
assert.Len(t, c.Diagnostics.Warnings, 1)
80
+
assert.Equal(t, WorkflowSkipped, c.Diagnostics.Warnings[0].Type)
83
+
func TestCompileWorkflow_CloneFalseWithShallowTrue(t *testing.T) {
85
+
Name: ".tangled/workflows/clone_skip.yml",
88
+
{Name: "Skip", Command: "echo skip"},
90
+
CloneOpts: CloneOpts{
96
+
c := Compiler{Trigger: trigger}
97
+
cp := c.Compile([]Workflow{wf})
99
+
assert.Len(t, cp.Workflows, 1)
100
+
assert.True(t, cp.Workflows[0].Clone.Skip)
101
+
assert.Len(t, c.Diagnostics.Warnings, 1)
102
+
assert.Equal(t, InvalidConfiguration, c.Diagnostics.Warnings[0].Type)