-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmatch_test.go
65 lines (61 loc) · 1.32 KB
/
match_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
// Copyright 2018 Drone.IO Inc
// Use of this software is governed by the Business Source License
// that can be found in the LICENSE file.
package plugin
import "testing"
func TestMatch(t *testing.T) {
tests := []struct {
name string
patterns []string
match bool
}{
// direct match
{
name: "octocat/Spoon-Fork",
patterns: []string{"octocat/Spoon-Fork"},
match: true,
},
// wildcard match
{
name: "octocat/Spoon-Fork",
patterns: []string{"octocat/*"},
match: true,
},
// wildcard match
{
name: "octocat/Spoon-Fork",
patterns: []string{"github/*", "octocat/*"},
match: true,
},
// wildcard match, case-insensitive
{
name: "OCTOCAT/HELLO-WORLD",
patterns: []string{"octocat/HELLO-world"},
match: true,
},
// match when no filter
{
name: "octocat/Spoon-Fork",
patterns: []string{},
match: true,
},
// no wildcard match
{
name: "octocat/Spoon-Fork",
patterns: []string{"github/*"},
match: false,
},
// no direct match
{
name: "octocat/Spoon-Fork",
patterns: []string{"octocat/Hello-World"},
match: false,
},
}
for _, test := range tests {
got, want := match(test.name, test.patterns), test.match
if got != want {
t.Errorf("Want matched %v, got %v", want, got)
}
}
}