forked from golangci/golangci-lint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpath_prefixer_test.go
37 lines (31 loc) · 982 Bytes
/
path_prefixer_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
package processors
import (
"go/token"
"testing"
"github.com/stretchr/testify/require"
"github.com/golangci/golangci-lint/pkg/result"
)
func TestPathPrefixer_Process(t *testing.T) {
paths := func(ps ...string) (issues []result.Issue) {
for _, p := range ps {
issues = append(issues, result.Issue{Pos: token.Position{Filename: p}})
}
return
}
for _, tt := range []struct {
name, prefix string
issues, want []result.Issue
}{
{"empty prefix", "", paths("some/path", "cool"), paths("some/path", "cool")},
{"prefix", "ok", paths("some/path", "cool"), paths("ok/some/path", "ok/cool")},
{"prefix slashed", "ok/", paths("some/path", "cool"), paths("ok/some/path", "ok/cool")},
} {
t.Run(tt.name, func(t *testing.T) {
r := require.New(t)
p := NewPathPrefixer(tt.prefix) //nolint:scopelint
got, err := p.Process(tt.issues) //nolint:scopelint
r.NoError(err, "prefixer should never error")
r.Equal(got, tt.want) //nolint:scopelint
})
}
}