github.com/ldez/golangci-lint@v1.10.1/pkg/result/processors/skip_files_test.go (about) 1 package processors 2 3 import ( 4 "go/token" 5 "testing" 6 7 "github.com/golangci/golangci-lint/pkg/result" 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func newFileIssue(file string) result.Issue { 12 return result.Issue{ 13 Pos: token.Position{ 14 Filename: file, 15 }, 16 } 17 } 18 19 func newTestSkipFiles(t *testing.T, patterns ...string) *SkipFiles { 20 p, err := NewSkipFiles(patterns) 21 assert.NoError(t, err) 22 return p 23 } 24 25 func TestSkipFiles(t *testing.T) { 26 processAssertSame(t, newTestSkipFiles(t), newFileIssue("any.go")) 27 28 processAssertEmpty(t, newTestSkipFiles(t, "file"), 29 newFileIssue("file.go"), 30 newFileIssue("file"), 31 newFileIssue("nofile.go")) 32 33 processAssertEmpty(t, newTestSkipFiles(t, ".*"), newFileIssue("any.go")) 34 35 processAssertEmpty(t, newTestSkipFiles(t, "a/b/c.go"), newFileIssue("a/b/c.go")) 36 processAssertSame(t, newTestSkipFiles(t, "a/b/c.go"), newFileIssue("a/b/d.go")) 37 38 processAssertEmpty(t, newTestSkipFiles(t, ".*\\.pb\\.go"), newFileIssue("a/b.pb.go")) 39 processAssertSame(t, newTestSkipFiles(t, ".*\\.pb\\.go"), newFileIssue("a/b.go")) 40 41 processAssertEmpty(t, newTestSkipFiles(t, ".*\\.pb\\.go$"), newFileIssue("a/b.pb.go")) 42 processAssertSame(t, newTestSkipFiles(t, ".*\\.pb\\.go$"), newFileIssue("a/b.go")) 43 } 44 45 func TestSkipFilesInvalidPattern(t *testing.T) { 46 p, err := NewSkipFiles([]string{"\\o"}) 47 assert.Error(t, err) 48 assert.Nil(t, p) 49 }