From 9572b7224f6ac16c0b8a9a3bbf8bd8a7c29f65e9 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Thu, 13 Jun 2024 22:52:31 +0200 Subject: [PATCH] restorer: windows test fixes --- internal/restic/node_xattr_all_test.go | 14 +++++++++++++- internal/restorer/fileswriter_other_test.go | 10 ++++++++++ internal/restorer/fileswriter_test.go | 9 +++++++-- internal/restorer/fileswriter_windows_test.go | 7 +++++++ 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 internal/restorer/fileswriter_other_test.go create mode 100644 internal/restorer/fileswriter_windows_test.go diff --git a/internal/restic/node_xattr_all_test.go b/internal/restic/node_xattr_all_test.go index 4e93330bc..56ce5e286 100644 --- a/internal/restic/node_xattr_all_test.go +++ b/internal/restic/node_xattr_all_test.go @@ -6,18 +6,30 @@ package restic import ( "os" "path/filepath" + "runtime" + "strings" "testing" rtest "github.com/restic/restic/internal/test" ) func setAndVerifyXattr(t *testing.T, file string, attrs []ExtendedAttribute) { + if runtime.GOOS == "windows" { + // windows seems to convert the xattr name to upper case + for i := range attrs { + attrs[i].Name = strings.ToUpper(attrs[i].Name) + } + } + node := Node{ + Type: "file", ExtendedAttributes: attrs, } rtest.OK(t, node.restoreExtendedAttributes(file)) - nodeActual := Node{} + nodeActual := Node{ + Type: "file", + } rtest.OK(t, nodeActual.fillExtendedAttributes(file, false)) rtest.Assert(t, nodeActual.sameExtendedAttributes(node), "xattr mismatch got %v expected %v", nodeActual.ExtendedAttributes, node.ExtendedAttributes) diff --git a/internal/restorer/fileswriter_other_test.go b/internal/restorer/fileswriter_other_test.go new file mode 100644 index 000000000..530a190e5 --- /dev/null +++ b/internal/restorer/fileswriter_other_test.go @@ -0,0 +1,10 @@ +//go:build !windows +// +build !windows + +package restorer + +import "syscall" + +func notEmptyDirError() error { + return syscall.ENOTEMPTY +} diff --git a/internal/restorer/fileswriter_test.go b/internal/restorer/fileswriter_test.go index b4252a96e..383a9e0d7 100644 --- a/internal/restorer/fileswriter_test.go +++ b/internal/restorer/fileswriter_test.go @@ -4,7 +4,7 @@ import ( "fmt" "os" "path/filepath" - "syscall" + "runtime" "testing" "github.com/restic/restic/internal/errors" @@ -72,7 +72,7 @@ func TestCreateFile(t *testing.T) { rtest.OK(t, os.Mkdir(path, 0o700)) rtest.OK(t, os.WriteFile(filepath.Join(path, "file"), []byte("data"), 0o400)) }, - err: syscall.ENOTEMPTY, + err: notEmptyDirError(), }, { name: "hardlinks", @@ -81,6 +81,11 @@ func TestCreateFile(t *testing.T) { rtest.OK(t, os.Link(path, path+"h")) }, check: func(t testing.TB, path string) { + if runtime.GOOS == "windows" { + // hardlinks are not supported on windows + return + } + data, err := os.ReadFile(path + "h") rtest.OK(t, err) rtest.Equals(t, "test-test-test-data", string(data), "unexpected content change") diff --git a/internal/restorer/fileswriter_windows_test.go b/internal/restorer/fileswriter_windows_test.go new file mode 100644 index 000000000..ec2b062f0 --- /dev/null +++ b/internal/restorer/fileswriter_windows_test.go @@ -0,0 +1,7 @@ +package restorer + +import "syscall" + +func notEmptyDirError() error { + return syscall.ERROR_DIR_NOT_EMPTY +}