mirror of
https://github.com/octoleo/restic.git
synced 2024-11-25 22:27:35 +00:00
restic: refactor node test
This commit is contained in:
parent
cc84884d2e
commit
ea9ad77e05
@ -198,63 +198,65 @@ func TestNodeRestoreAt(t *testing.T) {
|
|||||||
tempdir := t.TempDir()
|
tempdir := t.TempDir()
|
||||||
|
|
||||||
for _, test := range nodeTests {
|
for _, test := range nodeTests {
|
||||||
var nodePath string
|
t.Run("", func(t *testing.T) {
|
||||||
if test.ExtendedAttributes != nil {
|
var nodePath string
|
||||||
if runtime.GOOS == "windows" {
|
if test.ExtendedAttributes != nil {
|
||||||
// restic does not support xattrs on windows
|
if runtime.GOOS == "windows" {
|
||||||
return
|
// restic does not support xattrs on windows
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// tempdir might be backed by a filesystem that does not support
|
||||||
|
// extended attributes
|
||||||
|
nodePath = test.Name
|
||||||
|
defer func() {
|
||||||
|
_ = os.Remove(nodePath)
|
||||||
|
}()
|
||||||
|
} else {
|
||||||
|
nodePath = filepath.Join(tempdir, test.Name)
|
||||||
|
}
|
||||||
|
rtest.OK(t, test.CreateAt(context.TODO(), nodePath, nil))
|
||||||
|
rtest.OK(t, test.RestoreMetadata(nodePath))
|
||||||
|
|
||||||
|
if test.Type == "dir" {
|
||||||
|
rtest.OK(t, test.RestoreTimestamps(nodePath))
|
||||||
}
|
}
|
||||||
|
|
||||||
// tempdir might be backed by a filesystem that does not support
|
fi, err := os.Lstat(nodePath)
|
||||||
// extended attributes
|
rtest.OK(t, err)
|
||||||
nodePath = test.Name
|
|
||||||
defer func() {
|
|
||||||
_ = os.Remove(nodePath)
|
|
||||||
}()
|
|
||||||
} else {
|
|
||||||
nodePath = filepath.Join(tempdir, test.Name)
|
|
||||||
}
|
|
||||||
rtest.OK(t, test.CreateAt(context.TODO(), nodePath, nil))
|
|
||||||
rtest.OK(t, test.RestoreMetadata(nodePath))
|
|
||||||
|
|
||||||
if test.Type == "dir" {
|
n2, err := restic.NodeFromFileInfo(nodePath, fi)
|
||||||
rtest.OK(t, test.RestoreTimestamps(nodePath))
|
rtest.OK(t, err)
|
||||||
}
|
|
||||||
|
|
||||||
fi, err := os.Lstat(nodePath)
|
rtest.Assert(t, test.Name == n2.Name,
|
||||||
rtest.OK(t, err)
|
"%v: name doesn't match (%v != %v)", test.Type, test.Name, n2.Name)
|
||||||
|
rtest.Assert(t, test.Type == n2.Type,
|
||||||
|
"%v: type doesn't match (%v != %v)", test.Type, test.Type, n2.Type)
|
||||||
|
rtest.Assert(t, test.Size == n2.Size,
|
||||||
|
"%v: size doesn't match (%v != %v)", test.Size, test.Size, n2.Size)
|
||||||
|
|
||||||
n2, err := restic.NodeFromFileInfo(nodePath, fi)
|
if runtime.GOOS != "windows" {
|
||||||
rtest.OK(t, err)
|
rtest.Assert(t, test.UID == n2.UID,
|
||||||
|
"%v: UID doesn't match (%v != %v)", test.Type, test.UID, n2.UID)
|
||||||
rtest.Assert(t, test.Name == n2.Name,
|
rtest.Assert(t, test.GID == n2.GID,
|
||||||
"%v: name doesn't match (%v != %v)", test.Type, test.Name, n2.Name)
|
"%v: GID doesn't match (%v != %v)", test.Type, test.GID, n2.GID)
|
||||||
rtest.Assert(t, test.Type == n2.Type,
|
if test.Type != "symlink" {
|
||||||
"%v: type doesn't match (%v != %v)", test.Type, test.Type, n2.Type)
|
// On OpenBSD only root can set sticky bit (see sticky(8)).
|
||||||
rtest.Assert(t, test.Size == n2.Size,
|
if runtime.GOOS != "openbsd" && runtime.GOOS != "netbsd" && runtime.GOOS != "solaris" && test.Name == "testSticky" {
|
||||||
"%v: size doesn't match (%v != %v)", test.Size, test.Size, n2.Size)
|
rtest.Assert(t, test.Mode == n2.Mode,
|
||||||
|
"%v: mode doesn't match (0%o != 0%o)", test.Type, test.Mode, n2.Mode)
|
||||||
if runtime.GOOS != "windows" {
|
}
|
||||||
rtest.Assert(t, test.UID == n2.UID,
|
|
||||||
"%v: UID doesn't match (%v != %v)", test.Type, test.UID, n2.UID)
|
|
||||||
rtest.Assert(t, test.GID == n2.GID,
|
|
||||||
"%v: GID doesn't match (%v != %v)", test.Type, test.GID, n2.GID)
|
|
||||||
if test.Type != "symlink" {
|
|
||||||
// On OpenBSD only root can set sticky bit (see sticky(8)).
|
|
||||||
if runtime.GOOS != "openbsd" && runtime.GOOS != "netbsd" && runtime.GOOS != "solaris" && test.Name == "testSticky" {
|
|
||||||
rtest.Assert(t, test.Mode == n2.Mode,
|
|
||||||
"%v: mode doesn't match (0%o != 0%o)", test.Type, test.Mode, n2.Mode)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
AssertFsTimeEqual(t, "AccessTime", test.Type, test.AccessTime, n2.AccessTime)
|
AssertFsTimeEqual(t, "AccessTime", test.Type, test.AccessTime, n2.AccessTime)
|
||||||
AssertFsTimeEqual(t, "ModTime", test.Type, test.ModTime, n2.ModTime)
|
AssertFsTimeEqual(t, "ModTime", test.Type, test.ModTime, n2.ModTime)
|
||||||
if len(n2.ExtendedAttributes) == 0 {
|
if len(n2.ExtendedAttributes) == 0 {
|
||||||
n2.ExtendedAttributes = nil
|
n2.ExtendedAttributes = nil
|
||||||
}
|
}
|
||||||
rtest.Assert(t, reflect.DeepEqual(test.ExtendedAttributes, n2.ExtendedAttributes),
|
rtest.Assert(t, reflect.DeepEqual(test.ExtendedAttributes, n2.ExtendedAttributes),
|
||||||
"%v: xattrs don't match (%v != %v)", test.Name, test.ExtendedAttributes, n2.ExtendedAttributes)
|
"%v: xattrs don't match (%v != %v)", test.Name, test.ExtendedAttributes, n2.ExtendedAttributes)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user