restore: fix xattr filter test on windows

This commit is contained in:
Michael Eischer 2025-01-18 22:54:47 +01:00
parent 44cef25077
commit 5e8654c71d
1 changed files with 17 additions and 8 deletions

View File

@ -42,14 +42,11 @@ func setAndVerifyXattr(t *testing.T, file string, attrs []restic.ExtendedAttribu
func setAndVerifyXattrWithSelectFilter(t *testing.T, file string, testAttr []testXattrToRestore, xattrSelectFilter func(_ string) bool) { func setAndVerifyXattrWithSelectFilter(t *testing.T, file string, testAttr []testXattrToRestore, xattrSelectFilter func(_ string) bool) {
attrs := make([]restic.ExtendedAttribute, len(testAttr)) attrs := make([]restic.ExtendedAttribute, len(testAttr))
for i := range testAttr { for i := range testAttr {
attrs[i] = testAttr[i].xattr
}
if runtime.GOOS == "windows" {
// windows seems to convert the xattr name to upper case // windows seems to convert the xattr name to upper case
for i := range attrs { if runtime.GOOS == "windows" {
attrs[i].Name = strings.ToUpper(attrs[i].Name) testAttr[i].xattr.Name = strings.ToUpper(testAttr[i].xattr.Name)
} }
attrs[i] = testAttr[i].xattr
} }
node := &restic.Node{ node := &restic.Node{
@ -109,6 +106,18 @@ func TestOverwriteXattr(t *testing.T) {
}) })
} }
func uppercaseOnWindows(patterns []string) []string {
// windows seems to convert the xattr name to upper case
if runtime.GOOS == "windows" {
out := []string{}
for _, pattern := range patterns {
out = append(out, strings.ToUpper(pattern))
}
return out
}
return patterns
}
func TestOverwriteXattrWithSelectFilter(t *testing.T) { func TestOverwriteXattrWithSelectFilter(t *testing.T) {
dir := t.TempDir() dir := t.TempDir()
file := filepath.Join(dir, "file2") file := filepath.Join(dir, "file2")
@ -118,7 +127,7 @@ func TestOverwriteXattrWithSelectFilter(t *testing.T) {
// Set a filter as if the user passed in --include-xattr user.* // Set a filter as if the user passed in --include-xattr user.*
xattrSelectFilter1 := func(xattrName string) bool { xattrSelectFilter1 := func(xattrName string) bool {
shouldInclude, _ := filter.IncludeByPattern([]string{"user.*"}, noopWarnf)(xattrName) shouldInclude, _ := filter.IncludeByPattern(uppercaseOnWindows([]string{"user.*"}), noopWarnf)(xattrName)
return shouldInclude return shouldInclude
} }
@ -148,7 +157,7 @@ func TestOverwriteXattrWithSelectFilter(t *testing.T) {
// Set a filter as if the user passed in --include-xattr user.* // Set a filter as if the user passed in --include-xattr user.*
xattrSelectFilter2 := func(xattrName string) bool { xattrSelectFilter2 := func(xattrName string) bool {
shouldInclude, _ := filter.IncludeByPattern([]string{"user.o*", "user.comm*"}, noopWarnf)(xattrName) shouldInclude, _ := filter.IncludeByPattern(uppercaseOnWindows([]string{"user.o*", "user.comm*"}), noopWarnf)(xattrName)
return shouldInclude return shouldInclude
} }