-
Notifications
You must be signed in to change notification settings - Fork 0
/
loggercheck_test.go
84 lines (70 loc) · 1.73 KB
/
loggercheck_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
package loggercheck_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/tools/go/analysis/analysistest"
"github.com/george-maroun/tracecheck"
)
// N.B. Before running the tests you need to
// cd testdata/src/a && run
// go mod vendor
// This downloads the dependencies for the test data.
type dummyTestingErrorf struct {
*testing.T
}
func (t dummyTestingErrorf) Errorf(format string, args ...interface{}) {}
func TestLinter(t *testing.T) {
// TestData returns the effective filename of the program's "testdata" directory
testdata := analysistest.TestData()
testCases := []struct {
name string
patterns string
flags []string
wantError string
}{
{
name: "all",
patterns: "a/all",
flags: []string{""},
},
}
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
a := loggercheck.NewAnalyzer()
err := a.Flags.Parse(tc.flags)
require.NoError(t, err)
var result []*analysistest.Result
if tc.wantError != "" {
result = analysistest.Run(&dummyTestingErrorf{t}, testdata, a, tc.patterns)
} else {
result = analysistest.Run(t, testdata, a, tc.patterns)
}
require.Len(t, result, 1)
if tc.wantError != "" {
assert.Error(t, result[0].Err)
assert.ErrorContains(t, result[0].Err, tc.wantError)
}
})
}
}
func TestLinterFix(t *testing.T) {
testdata := analysistest.TestData()
testCases := []struct {
name string
dir string
}{
{
name: "fix_import",
dir: "a/fix_import",
},
}
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
a := loggercheck.NewAnalyzer()
analysistest.RunWithSuggestedFixes(t, testdata, a, tc.dir)
})
}
}