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