github.com/chenfeining/golangci-lint@v1.0.2-0.20230730162517-14c6c67868df/pkg/result/processors/processor_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/chenfeining/golangci-lint/pkg/result"
    10  )
    11  
    12  type issueTestCase struct {
    13  	Path     string
    14  	Line     int
    15  	Text     string
    16  	Linter   string
    17  	Severity string
    18  }
    19  
    20  func newIssueFromIssueTestCase(c issueTestCase) result.Issue {
    21  	return result.Issue{
    22  		Text:       c.Text,
    23  		FromLinter: c.Linter,
    24  		Pos: token.Position{
    25  			Filename: c.Path,
    26  			Line:     c.Line,
    27  		},
    28  	}
    29  }
    30  
    31  func newIssueFromTextTestCase(text string) result.Issue {
    32  	return result.Issue{
    33  		Text: text,
    34  	}
    35  }
    36  
    37  func process(t *testing.T, p Processor, issues ...result.Issue) []result.Issue {
    38  	t.Helper()
    39  
    40  	processedIssues, err := p.Process(issues)
    41  	assert.NoError(t, err)
    42  	return processedIssues
    43  }
    44  
    45  func processAssertSame(t *testing.T, p Processor, issues ...result.Issue) {
    46  	t.Helper()
    47  
    48  	processedIssues := process(t, p, issues...)
    49  	assert.Equal(t, issues, processedIssues)
    50  }
    51  
    52  func processAssertEmpty(t *testing.T, p Processor, issues ...result.Issue) {
    53  	t.Helper()
    54  
    55  	processedIssues := process(t, p, issues...)
    56  	assert.Empty(t, processedIssues)
    57  }