-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlint_test.go
68 lines (63 loc) · 1.69 KB
/
lint_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
package lint
import (
"reflect"
"testing"
)
func TestLintSource(t *testing.T) {
cases := []struct {
files map[string][]byte
expected []string
}{
{
files: map[string][]byte{
"t.go": []byte("package t\n\nfunc FirstFoo(){\n}\n\nfunc SecondFoo(){\n}"),
"t_test.go": []byte("package t\n\nfunc TestFirstFoo(t *testing.T){\n}\n\nfunc TestSecondFoo(t *testing.T){\n}"),
},
expected: nil,
},
{
files: map[string][]byte{
"t.go": []byte("package t\n\nfunc FirstFoo(){\n}\n\nfunc SecondFoo(){\n}"),
},
expected: []string{
"t.go:3:function FirstFoo is not covered any tests",
"t.go:6:function SecondFoo is not covered any tests",
},
},
{
files: map[string][]byte{
"t.go": []byte("package t\n\nfunc FirstFoo(){\n}\n\nfunc SecondFoo(){\n}"),
"t_test.go": []byte("package t\n\nfunc TestSecondFoo(t *testing.T){\n}"),
},
expected: []string{
"t.go:3:function FirstFoo is not covered any tests",
},
},
{
files: map[string][]byte{
"t.go": []byte("package t\n\n// FirstFoo\n// nolint: gotestlint\nfunc FirstFoo(){\n}\n\nfunc SecondFoo(){\n}"),
"t_test.go": []byte("package t\n\nfunc TestSecondFoo(t *testing.T){\n}"),
},
expected: nil,
},
}
linter := Linter{}
for _, c := range cases {
t.Run("", func(t *testing.T) {
act, err := linter.LintFiles(c.files)
if err != nil {
t.Error("unexpected erorr", err)
}
if !reflect.DeepEqual(c.expected, adviseToString(act)) {
t.Errorf("mistake expected: %v\nbut was: %v", c.expected, act)
}
})
}
}
func adviseToString(advs []Advise) []string {
var str []string
for _, problem := range advs {
str = append(str, problem.String())
}
return str
}