forked from golangci/golangci-lint
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgithub_test.go
74 lines (64 loc) · 1.59 KB
/
github_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package printers
import (
"bytes"
"context"
"go/token"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/golangci/golangci-lint/pkg/result"
)
func TestGithub_Print(t *testing.T) {
issues := []result.Issue{
{
FromLinter: "linter-a",
Severity: "warning",
Text: "some issue",
Pos: token.Position{
Filename: "path/to/filea.go",
Offset: 2,
Line: 10,
Column: 4,
},
},
{
FromLinter: "linter-b",
Severity: "error",
Text: "another issue",
SourceLines: []string{
"func foo() {",
"\tfmt.Println(\"bar\")",
"}",
},
Pos: token.Position{
Filename: "path/to/fileb.go",
Offset: 5,
Line: 300,
Column: 9,
},
},
}
buf := new(bytes.Buffer)
printer := NewGithub(buf)
err := printer.Print(context.Background(), issues)
require.NoError(t, err)
expected := `::warning file=path/to/filea.go,line=10,col=4::some issue (linter-a)
::error file=path/to/fileb.go,line=300,col=9::another issue (linter-b)
`
assert.Equal(t, expected, buf.String())
}
func TestFormatGithubIssue(t *testing.T) {
sampleIssue := result.Issue{
FromLinter: "sample-linter",
Text: "some issue",
Pos: token.Position{
Filename: "path/to/file.go",
Offset: 2,
Line: 10,
Column: 4,
},
}
require.Equal(t, "::error file=path/to/file.go,line=10,col=4::some issue (sample-linter)", formatIssueAsGithub(&sampleIssue))
sampleIssue.Pos.Column = 0
require.Equal(t, "::error file=path/to/file.go,line=10::some issue (sample-linter)", formatIssueAsGithub(&sampleIssue))
}