-
Notifications
You must be signed in to change notification settings - Fork 163
/
rule_id_test.go
106 lines (100 loc) · 1.94 KB
/
rule_id_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
100
101
102
103
104
105
106
package actionlint
import (
"strings"
"testing"
)
func TestCheckInvalidJobNames(t *testing.T) {
// Note: Empty string is already reported as error by parser
inputs := []string{
"-foo",
"v1.2.3",
"hello!",
"じょぶ",
"12345",
}
for _, input := range inputs {
tests := []struct {
where string
job *Job
expected string
}{
{
"jobs.<job_id>",
&Job{
ID: &String{Value: input, Pos: &Pos{}},
},
"invalid job ID",
},
{
"jobs.<job_id>.needs",
&Job{
ID: &String{Value: "test", Pos: &Pos{}},
Needs: []*String{
{Value: input, Pos: &Pos{}},
},
},
"invalid job ID",
},
{
"steps.*.id",
&Job{
Steps: []*Step{
{ID: &String{Value: input, Pos: &Pos{}}},
},
},
"invalid step ID",
},
}
for _, tc := range tests {
t.Run(input+"/"+tc.where, func(t *testing.T) {
r := NewRuleID()
r.VisitJobPre(tc.job)
for _, s := range tc.job.Steps {
r.VisitStep(s)
}
errs := r.Errs()
if len(errs) != 1 {
t.Fatalf("Wanted exactly one error but got %d errors: %v", len(errs), errs)
}
msg := errs[0].Error()
if !strings.Contains(msg, tc.expected) {
t.Errorf("Error message %q should contain %q", msg, tc.expected)
}
})
}
}
}
func TestCheckValidJobNames(t *testing.T) {
inputs := []string{
"foo-bar",
"foo_bar",
"foo--bar",
"foo__bar",
"_FOO123-",
"abcdefhijklmnopqrstuvwxyzABCDEFHIJKLMNOPQRSTUVWXYZ",
"_____",
"_-_-_",
}
for _, input := range inputs {
t.Run(input, func(t *testing.T) {
job := &Job{
ID: &String{Value: input, Pos: &Pos{}},
Needs: []*String{
{Value: input, Pos: &Pos{}},
},
Steps: []*Step{
{ID: &String{Value: input, Pos: &Pos{}}},
},
}
r := NewRuleID()
r.VisitJobPre(job)
for _, s := range job.Steps {
r.VisitStep(s)
}
errs := r.Errs()
if len(errs) > 0 {
t.Fatalf("Unexpected error(s): %#v", errs)
}
})
}
}