2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-22 10:58:55 +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 {