-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrule_test.go
69 lines (62 loc) · 1.46 KB
/
rule_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
package gitlabcodeowners
import (
"testing"
"github.com/chefe/gitlabcodeowners/testhelper"
)
func TestRule_parseRule(t *testing.T) {
t.Parallel()
tests := []struct {
name string
rule string
want rule
}{
{
name: "single owner",
rule: "/*.md @username",
want: rule{
pattern: pattern{value: "/*.md", normalized: "/*.md"},
owners: []string{"@username"},
},
},
{
name: "multiple owners",
rule: "/path/to/entry.txt @group @group/subgroup @user",
want: rule{
pattern: pattern{value: "/path/to/entry.txt", normalized: "/path/to/entry.txt"},
owners: []string{"@group", "@group/subgroup", "@user"},
},
},
{
name: "multiple owners with tabs",
rule: "/path/to/entry.txt\t@username\[email protected]",
want: rule{
pattern: pattern{value: "/path/to/entry.txt", normalized: "/path/to/entry.txt"},
owners: []string{"@username", "[email protected]"},
},
},
{
name: "entries with spaces",
rule: "folder with spaces/*.md @group",
want: rule{
pattern: pattern{value: "folder", normalized: "/**/folder"},
owners: []string{"with", "spaces/*.md", "@group"},
},
},
{
name: "no owner",
rule: "/file.md",
want: rule{
pattern: pattern{value: "/file.md", normalized: "/file.md"},
owners: []string{},
},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got := parseRule(tt.rule)
testhelper.DeepEqual(t, got, tt.want)
})
}
}