github.com/nozzle/golangci-lint@v1.49.0-nz3/pkg/printers/codeclimate_test.go (about)

     1  //nolint:dupl
     2  package printers
     3  
     4  import (
     5  	"bytes"
     6  	"context"
     7  	"go/token"
     8  	"testing"
     9  
    10  	"github.com/stretchr/testify/assert"
    11  	"github.com/stretchr/testify/require"
    12  
    13  	"github.com/golangci/golangci-lint/pkg/result"
    14  )
    15  
    16  func TestCodeClimate_Print(t *testing.T) {
    17  	issues := []result.Issue{
    18  		{
    19  			FromLinter: "linter-a",
    20  			Severity:   "warning",
    21  			Text:       "some issue",
    22  			Pos: token.Position{
    23  				Filename: "path/to/filea.go",
    24  				Offset:   2,
    25  				Line:     10,
    26  				Column:   4,
    27  			},
    28  		},
    29  		{
    30  			FromLinter: "linter-b",
    31  			Severity:   "error",
    32  			Text:       "another issue",
    33  			SourceLines: []string{
    34  				"func foo() {",
    35  				"\tfmt.Println(\"bar\")",
    36  				"}",
    37  			},
    38  			Pos: token.Position{
    39  				Filename: "path/to/fileb.go",
    40  				Offset:   5,
    41  				Line:     300,
    42  				Column:   9,
    43  			},
    44  		},
    45  	}
    46  
    47  	buf := new(bytes.Buffer)
    48  	printer := NewCodeClimate(buf)
    49  
    50  	err := printer.Print(context.Background(), issues)
    51  	require.NoError(t, err)
    52  
    53  	//nolint:lll
    54  	expected := `[{"description":"linter-a: some issue","severity":"warning","fingerprint":"BA73C5DF4A6FD8462FFF1D3140235777","location":{"path":"path/to/filea.go","lines":{"begin":10}}},{"description":"linter-b: another issue","severity":"error","fingerprint":"0777B4FE60242BD8B2E9B7E92C4B9521","location":{"path":"path/to/fileb.go","lines":{"begin":300}}}]`
    55  
    56  	assert.Equal(t, expected, buf.String())
    57  }