test: add tests for include By pattern
This commit is contained in:
parent
4e449ffaff
commit
1a7574e4b4
1 changed files with 59 additions and 0 deletions
59
cmd/restic/include_test.go
Normal file
59
cmd/restic/include_test.go
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestIncludeByPattern(t *testing.T) {
|
||||||
|
var tests = []struct {
|
||||||
|
filename string
|
||||||
|
include bool
|
||||||
|
}{
|
||||||
|
{filename: "/home/user/foo.go", include: true},
|
||||||
|
{filename: "/home/user/foo.c", include: false},
|
||||||
|
{filename: "/home/user/foobar", include: false},
|
||||||
|
{filename: "/home/user/foobar/x", include: false},
|
||||||
|
{filename: "/home/user/README", include: false},
|
||||||
|
{filename: "/home/user/README.md", include: true},
|
||||||
|
}
|
||||||
|
|
||||||
|
patterns := []string{"*.go", "README.md"}
|
||||||
|
|
||||||
|
for _, tc := range tests {
|
||||||
|
t.Run(tc.filename, func(t *testing.T) {
|
||||||
|
includeFunc := includeByPattern(patterns)
|
||||||
|
matched, _ := includeFunc(tc.filename)
|
||||||
|
if matched != tc.include {
|
||||||
|
t.Fatalf("wrong result for filename %v: want %v, got %v",
|
||||||
|
tc.filename, tc.include, matched)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestIncludeByInsensitivePattern(t *testing.T) {
|
||||||
|
var tests = []struct {
|
||||||
|
filename string
|
||||||
|
include bool
|
||||||
|
}{
|
||||||
|
{filename: "/home/user/foo.GO", include: true},
|
||||||
|
{filename: "/home/user/foo.c", include: false},
|
||||||
|
{filename: "/home/user/foobar", include: false},
|
||||||
|
{filename: "/home/user/FOObar/x", include: false},
|
||||||
|
{filename: "/home/user/README", include: false},
|
||||||
|
{filename: "/home/user/readme.MD", include: true},
|
||||||
|
}
|
||||||
|
|
||||||
|
patterns := []string{"*.go", "README.md"}
|
||||||
|
|
||||||
|
for _, tc := range tests {
|
||||||
|
t.Run(tc.filename, func(t *testing.T) {
|
||||||
|
includeFunc := includeByInsensitivePattern(patterns)
|
||||||
|
matched, _ := includeFunc(tc.filename)
|
||||||
|
if matched != tc.include {
|
||||||
|
t.Fatalf("wrong result for filename %v: want %v, got %v",
|
||||||
|
tc.filename, tc.include, matched)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue