forked from
tangled.org/core
fork
Configure Feed
Select the types of activity you want to include in your feed.
this repo has no description
fork
Configure Feed
Select the types of activity you want to include in your feed.
1package workflow
2
3import (
4 "strings"
5 "testing"
6
7 "github.com/stretchr/testify/assert"
8 "tangled.sh/tangled.sh/core/api/tangled"
9)
10
11var trigger = tangled.Pipeline_TriggerMetadata{
12 Kind: string(TriggerKindPush),
13 Push: &tangled.Pipeline_PushTriggerData{
14 Ref: "refs/heads/main",
15 OldSha: strings.Repeat("0", 40),
16 NewSha: strings.Repeat("f", 40),
17 },
18}
19
20var when = []Constraint{
21 {
22 Event: []string{"push"},
23 Branch: []string{"main"},
24 },
25}
26
27func TestCompileWorkflow_MatchingWorkflowWithSteps(t *testing.T) {
28 wf := Workflow{
29 Name: ".tangled/workflows/test.yml",
30 Engine: "nixery",
31 When: when,
32 CloneOpts: CloneOpts{}, // default true
33 }
34
35 c := Compiler{Trigger: trigger}
36 cp := c.Compile([]Workflow{wf})
37
38 assert.Len(t, cp.Workflows, 1)
39 assert.Equal(t, wf.Name, cp.Workflows[0].Name)
40 assert.False(t, cp.Workflows[0].Clone.Skip)
41 assert.False(t, c.Diagnostics.IsErr())
42}
43
44func TestCompileWorkflow_TriggerMismatch(t *testing.T) {
45 wf := Workflow{
46 Name: ".tangled/workflows/mismatch.yml",
47 Engine: "nixery",
48 When: []Constraint{
49 {
50 Event: []string{"push"},
51 Branch: []string{"master"}, // different branch
52 },
53 },
54 }
55
56 c := Compiler{Trigger: trigger}
57 cp := c.Compile([]Workflow{wf})
58
59 assert.Len(t, cp.Workflows, 0)
60 assert.Len(t, c.Diagnostics.Warnings, 1)
61 assert.Equal(t, WorkflowSkipped, c.Diagnostics.Warnings[0].Type)
62}
63
64func TestCompileWorkflow_CloneFalseWithShallowTrue(t *testing.T) {
65 wf := Workflow{
66 Name: ".tangled/workflows/clone_skip.yml",
67 Engine: "nixery",
68 When: when,
69 CloneOpts: CloneOpts{
70 Skip: true,
71 Depth: 1,
72 }, // false
73 }
74
75 c := Compiler{Trigger: trigger}
76 cp := c.Compile([]Workflow{wf})
77
78 assert.Len(t, cp.Workflows, 1)
79 assert.True(t, cp.Workflows[0].Clone.Skip)
80 assert.Len(t, c.Diagnostics.Warnings, 1)
81 assert.Equal(t, InvalidConfiguration, c.Diagnostics.Warnings[0].Type)
82}
83
84func TestCompileWorkflow_MissingEngine(t *testing.T) {
85 wf := Workflow{
86 Name: ".tangled/workflows/missing_engine.yml",
87 When: when,
88 Engine: "",
89 }
90
91 c := Compiler{Trigger: trigger}
92 cp := c.Compile([]Workflow{wf})
93
94 assert.Len(t, cp.Workflows, 0)
95 assert.Len(t, c.Diagnostics.Errors, 1)
96 assert.Equal(t, MissingEngine, c.Diagnostics.Errors[0].Error)
97}