-
Notifications
You must be signed in to change notification settings - Fork 163
/
rule_test.go
76 lines (68 loc) · 1.67 KB
/
rule_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
package actionlint
import (
"bytes"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestRuleBaseSetGetConfig(t *testing.T) {
r := NewRuleBase("", "")
if r.Config() != nil {
t.Error("Config must be nil after creating a rule")
}
want := &Config{}
r.SetConfig(want)
if have := r.Config(); have != want {
t.Errorf("Wanted config %v but got %v", want, have)
}
}
func TestRuleBaseErrorfAndErrs(t *testing.T) {
r := NewRuleBase("dummy name", "dummy description")
errs := r.Errs()
if len(errs) > 0 {
t.Error("no error is expected", errs)
}
r.Error(&Pos{Line: 1, Col: 2}, "this is test 1")
r.Errorf(&Pos{Line: 3, Col: 4}, "this is test %d", 2)
errs = r.Errs()
if len(errs) != 2 {
t.Error("wanted 2 errors but have", errs)
}
want := []*Error{
{
Message: "this is test 1",
Line: 1,
Column: 2,
Kind: "dummy name",
},
{
Message: "this is test 2",
Line: 3,
Column: 4,
Kind: "dummy name",
},
}
if diff := cmp.Diff(errs, want); diff != "" {
t.Error("unexpected errors from Errs() method:", diff)
}
}
func TestRuleBaseDebugOutput(t *testing.T) {
r := NewRuleBase("dummy-name", "")
r.Debug("this %s output", "is not")
b := &bytes.Buffer{}
r.EnableDebug(b)
r.Debug("this %s output!", "IS")
have := b.String()
want := "[dummy-name] this IS output!\n"
if want != have {
t.Errorf("wanted %q as debug output but have %q", want, have)
}
}
func TestRuleBaseNameAndDescription(t *testing.T) {
r := NewRuleBase("dummy name", "dummy description")
if r.Name() != "dummy name" {
t.Errorf("name is unexpected: %q", r.Name())
}
if r.Description() != "dummy description" {
t.Errorf("description is unexpected: %q", r.Description())
}
}