github.com/elek/golangci-lint@v1.42.2-0.20211208090441-c05b7fcb3a9a/pkg/result/processors/path_prefixer_test.go (about) 1 package processors 2 3 import ( 4 "go/token" 5 "testing" 6 7 "github.com/stretchr/testify/require" 8 9 "github.com/elek/golangci-lint/pkg/result" 10 ) 11 12 func TestPathPrefixer_Process(t *testing.T) { 13 paths := func(ps ...string) (issues []result.Issue) { 14 for _, p := range ps { 15 issues = append(issues, result.Issue{Pos: token.Position{Filename: p}}) 16 } 17 return 18 } 19 for _, tt := range []struct { 20 name, prefix string 21 issues, want []result.Issue 22 }{ 23 {"empty prefix", "", paths("some/path", "cool"), paths("some/path", "cool")}, 24 {"prefix", "ok", paths("some/path", "cool"), paths("ok/some/path", "ok/cool")}, 25 {"prefix slashed", "ok/", paths("some/path", "cool"), paths("ok/some/path", "ok/cool")}, 26 } { 27 t.Run(tt.name, func(t *testing.T) { 28 r := require.New(t) 29 30 p := NewPathPrefixer(tt.prefix) 31 got, err := p.Process(tt.issues) 32 r.NoError(err, "prefixer should never error") 33 34 r.Equal(got, tt.want) 35 }) 36 } 37 }