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
|
package filter_test
import (
"testing"
"github.com/restic/restic/internal/filter"
rtest "github.com/restic/restic/internal/test"
)
func TestValidPatterns(t *testing.T) {
// Test invalid patterns are detected and returned
t.Run("detect-invalid-patterns", func(t *testing.T) {
err := filter.ValidatePatterns([]string{"*.foo", "*[._]log[.-][0-9]", "!*[._]log[.-][0-9]"})
rtest.Assert(t, err != nil, "Expected invalid patterns to be detected")
if ip, ok := err.(*filter.InvalidPatternError); ok {
rtest.Equals(t, ip.InvalidPatterns, []string{"*[._]log[.-][0-9]", "!*[._]log[.-][0-9]"})
} else {
t.Errorf("wrong error type %v", err)
}
})
// Test all patterns defined in matchTests are valid
patterns := make([]string, 0)
for _, data := range matchTests {
patterns = append(patterns, data.pattern)
}
t.Run("validate-patterns", func(t *testing.T) {
err := filter.ValidatePatterns(patterns)
if err != nil {
t.Error(err)
}
})
// Test all patterns defined in childMatchTests are valid
childPatterns := make([]string, 0)
for _, data := range childMatchTests {
childPatterns = append(childPatterns, data.pattern)
}
t.Run("validate-child-patterns", func(t *testing.T) {
err := filter.ValidatePatterns(childPatterns)
if err != nil {
t.Error(err)
}
})
}
|