1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2024-12-23 00:07:25 +00:00

filter: test some corner cases

This commit is contained in:
Michael Eischer 2020-10-07 17:06:47 +02:00
parent 0ae02f3030
commit fdd3b14db3

View file

@ -244,6 +244,7 @@ var filterListTests = []struct {
path string path string
match bool match bool
}{ }{
{[]string{}, "/foo/bar/test.go", false},
{[]string{"*.go"}, "/foo/bar/test.go", true}, {[]string{"*.go"}, "/foo/bar/test.go", true},
{[]string{"*.c"}, "/foo/bar/test.go", false}, {[]string{"*.c"}, "/foo/bar/test.go", false},
{[]string{"*.go", "*.c"}, "/foo/bar/test.go", true}, {[]string{"*.go", "*.c"}, "/foo/bar/test.go", true},
@ -279,6 +280,38 @@ func ExampleList() {
// match: true // match: true
} }
func TestInvalidStrs(t *testing.T) {
_, err := filter.Match("test", "")
if err == nil {
t.Error("Match accepted invalid path")
}
_, err = filter.ChildMatch("test", "")
if err == nil {
t.Error("ChildMatch accepted invalid path")
}
patterns := []string{"test"}
_, _, err = filter.List(patterns, "")
if err == nil {
t.Error("List accepted invalid path")
}
}
func TestInvalidPattern(t *testing.T) {
patterns := []string{"test/["}
_, _, err := filter.List(patterns, "test/example")
if err == nil {
t.Error("List accepted invalid pattern")
}
patterns = []string{"test/**/["}
_, _, err = filter.List(patterns, "test/example")
if err == nil {
t.Error("List accepted invalid pattern")
}
}
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 {