-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmatchers_test.go
More file actions
81 lines (75 loc) · 2.12 KB
/
Copy pathmatchers_test.go
File metadata and controls
81 lines (75 loc) · 2.12 KB
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
75
76
77
78
79
80
package gomodguard_test
import (
"regexp"
"testing"
"github.com/stretchr/testify/assert"
"github.com/ryancurrah/gomodguard/v2"
)
func TestMatchers(t *testing.T) {
tests := map[string]struct {
matcher gomodguard.Matcher
input string
wantMatch bool
}{
"exact match": {
matcher: gomodguard.ExactMatcher{Target: "github.com/foo/bar"},
input: "github.com/foo/bar",
wantMatch: true,
},
"exact no match different version": {
matcher: gomodguard.ExactMatcher{Target: "github.com/foo/bar"},
input: "github.com/foo/bar/v2",
wantMatch: false,
},
"exact no match partial": {
matcher: gomodguard.ExactMatcher{Target: "github.com/foo/bar"},
input: "github.com/foo",
wantMatch: false,
},
"prefix match subpath": {
matcher: gomodguard.PrefixMatcher{Prefix: "golang.org"},
input: "golang.org/x/mod",
wantMatch: true,
},
"prefix match exact": {
matcher: gomodguard.PrefixMatcher{Prefix: "golang.org"},
input: "golang.org",
wantMatch: true,
},
"prefix match case insensitive with whitespace": {
matcher: gomodguard.PrefixMatcher{Prefix: "golang.org"},
input: " Golang.Org/x/tools ",
wantMatch: true,
},
"prefix no match different domain": {
matcher: gomodguard.PrefixMatcher{Prefix: "golang.org"},
input: "github.com/golang",
wantMatch: false,
},
"regex match mod": {
matcher: gomodguard.RegexMatcher{Regex: regexp.MustCompile(`golang\.org/x/.*`)},
input: "golang.org/x/mod",
wantMatch: true,
},
"regex match tools": {
matcher: gomodguard.RegexMatcher{Regex: regexp.MustCompile(`golang\.org/x/.*`)},
input: "golang.org/x/tools",
wantMatch: true,
},
"regex no match": {
matcher: gomodguard.RegexMatcher{Regex: regexp.MustCompile(`golang\.org/x/.*`)},
input: "golang.org/dl",
wantMatch: false,
},
"regex nil never matches": {
matcher: gomodguard.RegexMatcher{Regex: nil},
input: "anything",
wantMatch: false,
},
}
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
assert.Equal(t, tc.wantMatch, tc.matcher.Match(tc.input))
})
}
}