-
Notifications
You must be signed in to change notification settings - Fork 48
/
duplicated_pattern_test.go
64 lines (55 loc) · 1.45 KB
/
duplicated_pattern_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
package check_test
import (
"context"
"testing"
"github.com/mszostok/codeowners-validator/internal/check"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestDuplicatedPattern(t *testing.T) {
tests := map[string]struct {
codeownersInput string
expectedIssues []check.Issue
}{
"Should report info about duplicated entries": {
codeownersInput: `
* @global-owner1 @global-owner2
/build/logs/ @doctocat
/build/logs/ @doctocat
/script @mszostok
/script m.t@g.com
`,
expectedIssues: []check.Issue{
{
Severity: check.Error,
LineNo: nil,
Message: `Pattern "/build/logs/" is defined 2 times in lines:
* 4: with owners: [@doctocat]
* 5: with owners: [@doctocat]`,
},
{
Severity: check.Error,
LineNo: nil,
Message: `Pattern "/script" is defined 2 times in lines:
* 7: with owners: [@mszostok]
* 8: with owners: [m.t@g.com]`,
},
},
},
"Should not report any issues with correct CODEOWNERS file": {
codeownersInput: check.FixtureValidCODEOWNERS,
expectedIssues: nil,
},
}
for tn, tc := range tests {
t.Run(tn, func(t *testing.T) {
// given
sut := check.NewDuplicatedPattern()
// when
out, err := sut.Check(context.TODO(), check.LoadInput(tc.codeownersInput))
// then
require.NoError(t, err)
assert.ElementsMatch(t, tc.expectedIssues, out.Issues)
})
}
}