github.com/ldez/golangci-lint@v1.10.1/pkg/result/processors/exclude_test.go (about) 1 package processors 2 3 import ( 4 "testing" 5 6 "github.com/golangci/golangci-lint/pkg/result" 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func newTextIssue(text string) result.Issue { 11 return result.Issue{ 12 Text: text, 13 } 14 } 15 16 func process(t *testing.T, p Processor, issues ...result.Issue) []result.Issue { 17 processedIssues, err := p.Process(issues) 18 assert.NoError(t, err) 19 return processedIssues 20 } 21 22 func processAssertSame(t *testing.T, p Processor, issues ...result.Issue) { 23 processedIssues := process(t, p, issues...) 24 assert.Equal(t, issues, processedIssues) 25 } 26 27 func processAssertEmpty(t *testing.T, p Processor, issues ...result.Issue) { 28 processedIssues := process(t, p, issues...) 29 assert.Empty(t, processedIssues) 30 } 31 32 func TestExclude(t *testing.T) { 33 p := NewExclude("^exclude$") 34 texts := []string{"excLude", "1", "", "exclud", "notexclude"} 35 var issues []result.Issue 36 for _, t := range texts { 37 issues = append(issues, newTextIssue(t)) 38 } 39 40 processedIssues := process(t, p, issues...) 41 assert.Len(t, processedIssues, len(issues)-1) 42 43 var processedTexts []string 44 for _, i := range processedIssues { 45 processedTexts = append(processedTexts, i.Text) 46 } 47 assert.Equal(t, texts[1:], processedTexts) 48 } 49 50 func TestNoExclude(t *testing.T) { 51 processAssertSame(t, NewExclude(""), newTextIssue("test")) 52 }