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