-
Notifications
You must be signed in to change notification settings - Fork 163
/
availability_test.go
70 lines (64 loc) · 1.69 KB
/
availability_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
package actionlint
import (
"regexp"
"testing"
)
func TestWorkflowKeyAvailability(t *testing.T) {
for _, key := range allWorkflowKeys {
t.Run(key, func(t *testing.T) {
ctx, sp := WorkflowKeyAvailability(key)
if ctx == nil || sp == nil {
t.Error("workflow key has not availability info:", key)
}
if len(ctx) == 0 {
t.Error("no context is available for key", key)
}
r := regexp.MustCompile(`^[a-z][a-z0-9_]*$`)
for _, c := range ctx {
if !r.MatchString(c) {
t.Errorf("context %q does not match to pattern %s", c, r)
}
}
for _, s := range sp {
if !r.MatchString(s) {
t.Errorf("context %q does not match to pattern %s", s, r)
}
ks, ok := SpecialFunctionNames[s]
if !ok {
t.Errorf("special function %q is not registered in SpecialFunctionNames: %v", s, SpecialFunctionNames)
}
ok = false
for _, k := range ks {
if k == key {
ok = true
break
}
}
if !ok {
t.Errorf("Key %q is not in candidates of special function %q: %v", key, s, ks)
}
}
})
}
ctx, sp := WorkflowKeyAvailability("unknown.workflow.key")
if len(ctx) != 0 {
t.Error("some context was returned", ctx)
}
if len(sp) != 0 {
t.Error("some special function name was returned", sp)
}
}
func TestSpecialFunctionNames(t *testing.T) {
if len(SpecialFunctionNames) == 0 {
t.Error("No special function is registered in SpecialFunctionNames")
}
r := regexp.MustCompile(`^[a-z][a-z0-9_]*$`)
for f, ws := range SpecialFunctionNames {
if len(ws) == 0 {
t.Errorf("No workflow key is available for special function %q", f)
}
if !r.MatchString(f) {
t.Errorf("Special function name does not match to pattern %s", r)
}
}
}