1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2024-12-23 08:16:36 +00:00
restic/internal/fs/node_xattr_all_test.go

58 lines
1.3 KiB
Go
Raw Normal View History

//go:build darwin || freebsd || linux || solaris || windows
// +build darwin freebsd linux solaris windows
package fs
import (
"os"
"path/filepath"
2024-06-13 20:52:31 +00:00
"runtime"
"strings"
"testing"
"github.com/restic/restic/internal/restic"
rtest "github.com/restic/restic/internal/test"
)
func setAndVerifyXattr(t *testing.T, file string, attrs []restic.ExtendedAttribute) {
2024-06-13 20:52:31 +00:00
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 := &restic.Node{
2024-07-09 17:51:44 +00:00
Type: restic.NodeTypeFile,
ExtendedAttributes: attrs,
}
rtest.OK(t, nodeRestoreExtendedAttributes(node, file))
nodeActual := &restic.Node{
2024-07-09 17:51:44 +00:00
Type: restic.NodeTypeFile,
2024-06-13 20:52:31 +00:00
}
rtest.OK(t, nodeFillExtendedAttributes(nodeActual, file, false))
rtest.Assert(t, nodeActual.Equals(*node), "xattr mismatch got %v expected %v", nodeActual.ExtendedAttributes, node.ExtendedAttributes)
}
func TestOverwriteXattr(t *testing.T) {
dir := t.TempDir()
file := filepath.Join(dir, "file")
rtest.OK(t, os.WriteFile(file, []byte("hello world"), 0o600))
setAndVerifyXattr(t, file, []restic.ExtendedAttribute{
{
Name: "user.foo",
Value: []byte("bar"),
},
})
setAndVerifyXattr(t, file, []restic.ExtendedAttribute{
{
Name: "user.other",
Value: []byte("some"),
},
})
}