2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-22 21:05:10 +00:00

Add tests for insensitive variants of filter methods

This commit is contained in:
Johannes Hertenstein 2018-10-16 23:29:44 +02:00 committed by Alexander Neumann
parent c13f79da02
commit 5fe6de219d
2 changed files with 54 additions and 0 deletions

View File

@ -36,6 +36,33 @@ func TestRejectByPattern(t *testing.T) {
} }
} }
func TestRejectByInsensitivePattern(t *testing.T) {
var tests = []struct {
filename string
reject bool
}{
{filename: "/home/user/foo.GO", reject: true},
{filename: "/home/user/foo.c", reject: false},
{filename: "/home/user/foobar", reject: false},
{filename: "/home/user/FOObar/x", reject: true},
{filename: "/home/user/README", reject: false},
{filename: "/home/user/readme.md", reject: true},
}
patterns := []string{"*.go", "README.md", "/home/user/foobar/*"}
for _, tc := range tests {
t.Run("", func(t *testing.T) {
reject := rejectByInsensitivePattern(patterns)
res := reject(tc.filename)
if res != tc.reject {
t.Fatalf("wrong result for filename %v: want %v, got %v",
tc.filename, tc.reject, res)
}
})
}
}
func TestIsExcludedByFile(t *testing.T) { func TestIsExcludedByFile(t *testing.T) {
const ( const (
tagFilename = "CACHEDIR.TAG" tagFilename = "CACHEDIR.TAG"

View File

@ -279,6 +279,33 @@ func ExampleList() {
// match: true // match: true
} }
var filterInsensitiveListTests = []struct {
patterns []string
path string
match bool
}{
{[]string{"*.go"}, "/foo/bar/test.go", true},
{[]string{"test.go"}, "/foo/bar/test.go", true},
{[]string{"test.go"}, "/foo/bar/TEST.go", true},
{[]string{"BAR"}, "/foo/BAR/TEST.go", true},
}
func TestInsensitiveList(t *testing.T) {
for i, test := range filterInsensitiveListTests {
match, _, err := filter.InsensitiveList(test.patterns, test.path)
if err != nil {
t.Errorf("test %d failed: expected no error for patterns %q, but error returned: %v",
i, test.patterns, err)
continue
}
if match != test.match {
t.Errorf("test %d: filter.InsensitiveList(%q, %q): expected %v, got %v",
i, test.patterns, test.path, test.match, match)
}
}
}
func extractTestLines(t testing.TB) (lines []string) { func extractTestLines(t testing.TB) (lines []string) {
f, err := os.Open("testdata/libreoffice.txt.bz2") f, err := os.Open("testdata/libreoffice.txt.bz2")
if err != nil { if err != nil {