github.com/nozzle/golangci-lint@v1.49.0-nz3/pkg/printers/checkstyle_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 TestCheckstyle_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 := NewCheckstyle(buf) 49 50 err := printer.Print(context.Background(), issues) 51 require.NoError(t, err) 52 53 //nolint:lll 54 expected := "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\r\n<checkstyle version=\"5.0\">\r\n <file name=\"path/to/filea.go\">\r\n <error column=\"4\" line=\"10\" message=\"some issue\" severity=\"warning\" source=\"linter-a\">\r\n </error>\r\n </file>\r\n <file name=\"path/to/fileb.go\">\r\n <error column=\"9\" line=\"300\" message=\"another issue\" severity=\"error\" source=\"linter-b\">\r\n </error>\r\n </file>\r\n</checkstyle>\n" 55 56 assert.Equal(t, expected, buf.String()) 57 }