-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathignore_test.go
More file actions
116 lines (102 loc) · 2.96 KB
/
ignore_test.go
File metadata and controls
116 lines (102 loc) · 2.96 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package main
import (
"flag"
"testing"
)
func testNOPConfigfunc() (string, error) { return "", nil }
func TestIgnore(t *testing.T) {
cfg := newConfig(flag.NewFlagSet(Name, flag.ContinueOnError), testNOPConfigfunc)
cfg.ignoreBases.v = ".profile,.ds_store,.bashrc"
cfg.ignoreContains.v = "/pkg/mod/,tmp"
cfg.ignoreRegexes.v = `.*\/Library\/.*Mobile.*\/`
err := cfg.compile()
if err != nil {
t.Fatal(err)
}
testCases := []struct {
dir string
base string
expect string
}{
{"/home/user", ".bashrc", "bases"},
{"/home/user", ".profile", "bases"},
{"/home/user", ".ds_store", "bases"},
{"/pkg", "mod/cache/download", "contains"},
{"/var/tmp", "testfile.gz", "contains"},
{"~/Library", "Mobile Documents/phone.txt", "regexes"},
}
for ix, tc := range testCases {
got := cfg.ignore(tc.dir + "/" + tc.base)
if got != tc.expect {
t.Error(ix, tc.dir, tc.base, "Got", got, "Expect", tc.expect)
}
}
}
func TestIgnoreBases(t *testing.T) {
cfg := newConfig(flag.NewFlagSet(Name, flag.ContinueOnError), testNOPConfigfunc)
cfg.ignoreBases.v = ".profile,.DS_Store:cache"
err := cfg.compile()
if err != nil {
t.Fatal(err)
}
testCases := []struct {
base string
ignored bool
}{
{".bashrc", false},
{".profile", true},
{".ds_store", false}, // Must be exact match, including case
}
for ix, tc := range testCases {
if cfg.matchesBases(tc.base) != tc.ignored {
t.Error(ix, tc.base, "Expected", tc.ignored)
}
}
}
func TestIgnoreContains(t *testing.T) {
cfg := newConfig(flag.NewFlagSet(Name, flag.ContinueOnError), testNOPConfigfunc)
cfg.ignoreContains.v = ".bashr,/go/pkg/mod/,s_sto" // Include case-mismatches
err := cfg.compile()
if err != nil {
t.Fatal(err)
}
testCases := []struct {
path string
ignored bool
}{
{".profile", false},
{"/home/findactive/.bashrc", true},
{"/home/findactive/Desktop/.DS_Store", true},
{"/home/findactive/go/pkg/mod/cache/download/sumdb/sum.golang.org/lookup/golang.org/x/tools@v0.6.0", true},
{"/home/findactive/go/pkg/mod/cache/download/sumdb/sum.golang.org/lookup/golang.org/x/term@v0.5.0", true},
{"/home/findactive/go/pkg/mod/cache/download/sumdb/sum.golang.org/lookup/golang.org/x/text@v0.14.0", true},
}
for ix, tc := range testCases {
if cfg.matchesContains(tc.path) != tc.ignored {
t.Error(ix, tc.path, "Expected", tc.ignored)
}
}
}
func TestIgnoreRegexes(t *testing.T) {
cfg := newConfig(flag.NewFlagSet(Name, flag.ContinueOnError), testNOPConfigfunc)
cfg.ignoreRegexes.v = `.*profile$,\.bashrc$,.*\/go\/pkg\/.*`
err := cfg.compile()
if err != nil {
t.Fatal(err)
}
testCases := []struct {
path string
ignored bool
}{
{".profile", true},
{".profile/no", false},
{"/home/findactive/.bashrc", true},
{"/home/findactive/Desktop/.DS_Store", false},
{"/home/findactive/go/pkg/mod/cache/download/text@v0.14.0", true},
}
for ix, tc := range testCases {
if cfg.matchesRegexes(tc.path) != tc.ignored {
t.Error(ix, tc.path, "Expected", tc.ignored)
}
}
}