forked from rhysd/actionlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rule_workflow_call_test.go
99 lines (88 loc) · 1.88 KB
/
rule_workflow_call_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package actionlint
import (
"strings"
"testing"
)
func TestRuleWorkflowCallCheckWorkflowCallUsesFormat(t *testing.T) {
tests := []struct {
uses string
ok bool
}{
{"owner/repo/x.yml@ref", true},
{"owner/repo/x.yml@@", true},
{"owner/repo/x.yml@release/v1", true},
{"${{ env.FOO }}", true},
{"./path/to/x.yml@ref", false},
{"/path/to/x.yml@ref", false},
{"owner/x.yml@ref", false},
{"owner/repo@ref", false},
{"owner/repo/x.yml", false},
{"/repo/x.yml@ref", false},
{"owner//x.yml@ref", false},
{"owner/repo/@ref", false},
{"owner/repo/x.yml@", false},
}
for _, tc := range tests {
t.Run(tc.uses, func(t *testing.T) {
r := NewRuleWorkflowCall()
j := &Job{
WorkflowCall: &WorkflowCall{
Uses: &String{
Value: tc.uses,
Pos: &Pos{},
},
},
}
err := r.VisitJobPre(j)
if err != nil {
t.Fatal(err)
}
errs := r.Errs()
if tc.ok && len(errs) > 0 {
t.Fatalf("Error occurred: %v", errs)
}
if !tc.ok {
if len(errs) > 2 || len(errs) == 0 {
t.Fatalf("Wanted one error but have: %v", errs)
}
}
})
}
}
func TestRuleWorkflowCallCheckCannotCallNestedly(t *testing.T) {
w := &Workflow{
On: []Event{
&WorkflowCallEvent{
Pos: &Pos{
Line: 12,
Col: 34,
},
},
},
}
j := &Job{
WorkflowCall: &WorkflowCall{
Uses: &String{
Value: "o/r/w.yaml@r",
Pos: &Pos{},
},
},
}
r := NewRuleWorkflowCall()
if err := r.VisitWorkflowPre(w); err != nil {
t.Fatal(err)
}
if err := r.VisitJobPre(j); err != nil {
t.Fatal(err)
}
err := r.Errs()[0]
msg := err.Error()
want := "reusable workflow cannot be nested"
if !strings.Contains(msg, want) {
t.Errorf("error message %q does not contain expected message %q", msg, want)
}
want = "line:12,col:34"
if !strings.Contains(msg, want) {
t.Errorf("error message %q does not contain proper position %q", msg, want)
}
}