2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-23 11:28:54 +00:00

Merge pull request #2257 from gliptak/windows1

Don't run TestMetadataChanged test on Windows
This commit is contained in:
Alexander Neumann 2019-04-28 08:39:00 +02:00
commit 37cb82b28b
2 changed files with 104 additions and 90 deletions

View File

@ -0,0 +1,98 @@
// +build !windows
package archiver
import (
"context"
"os"
"syscall"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/restic/restic/internal/checker"
"github.com/restic/restic/internal/fs"
"github.com/restic/restic/internal/restic"
)
func TestMetadataChanged(t *testing.T) {
files := TestDir{
"testfile": TestFile{
Content: "foo bar test file",
},
}
tempdir, repo, cleanup := prepareTempdirRepoSrc(t, files)
defer cleanup()
back := fs.TestChdir(t, tempdir)
defer back()
// get metadata
fi := lstat(t, "testfile")
want, err := restic.NodeFromFileInfo("testfile", fi)
if err != nil {
t.Fatal(err)
}
fs := &StatFS{
FS: fs.Local{},
OverrideLstat: map[string]os.FileInfo{
"testfile": fi,
},
}
snapshotID, node2 := snapshot(t, repo, fs, restic.ID{}, "testfile")
// set some values so we can then compare the nodes
want.Content = node2.Content
want.Path = ""
want.ExtendedAttributes = nil
// make sure that metadata was recorded successfully
if !cmp.Equal(want, node2) {
t.Fatalf("metadata does not match:\n%v", cmp.Diff(want, node2))
}
// modify the mode
stat, ok := fi.Sys().(*syscall.Stat_t)
if ok {
// change a few values
stat.Mode = 0400
stat.Uid = 1234
stat.Gid = 1235
// wrap the os.FileInfo so we can return a modified stat_t
fi = wrappedFileInfo{
FileInfo: fi,
sys: stat,
mode: 0400,
}
fs.OverrideLstat["testfile"] = fi
} else {
// skip the test on this platform
t.Skipf("unable to modify os.FileInfo, Sys() returned %T", fi.Sys())
}
want, err = restic.NodeFromFileInfo("testfile", fi)
if err != nil {
t.Fatal(err)
}
// make another snapshot
snapshotID, node3 := snapshot(t, repo, fs, snapshotID, "testfile")
// set some values so we can then compare the nodes
want.Content = node2.Content
want.Path = ""
want.ExtendedAttributes = nil
// make sure that metadata was recorded successfully
if !cmp.Equal(want, node3) {
t.Fatalf("metadata does not match:\n%v", cmp.Diff(want, node2))
}
// make sure the content matches
TestEnsureFileContent(context.Background(), t, repo, "testfile", node3, files["testfile"].(TestFile))
checker.TestCheckRepo(t, repo)
}

View File

@ -14,7 +14,6 @@ import (
"testing" "testing"
"time" "time"
"github.com/google/go-cmp/cmp"
"github.com/restic/restic/internal/checker" "github.com/restic/restic/internal/checker"
"github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/errors"
"github.com/restic/restic/internal/fs" "github.com/restic/restic/internal/fs"
@ -126,9 +125,9 @@ func saveFile(t testing.TB, repo restic.Repository, filename string, filesystem
func TestArchiverSaveFile(t *testing.T) { func TestArchiverSaveFile(t *testing.T) {
var tests = []TestFile{ var tests = []TestFile{
TestFile{Content: ""}, {Content: ""},
TestFile{Content: "foo"}, {Content: "foo"},
TestFile{Content: string(restictest.Random(23, 12*1024*1024+1287898))}, {Content: string(restictest.Random(23, 12*1024*1024+1287898))},
} }
for _, testfile := range tests { for _, testfile := range tests {
@ -204,9 +203,9 @@ func TestArchiverSaveFileReaderFS(t *testing.T) {
func TestArchiverSave(t *testing.T) { func TestArchiverSave(t *testing.T) {
var tests = []TestFile{ var tests = []TestFile{
TestFile{Content: ""}, {Content: ""},
TestFile{Content: "foo"}, {Content: "foo"},
TestFile{Content: string(restictest.Random(23, 12*1024*1024+1287898))}, {Content: string(restictest.Random(23, 12*1024*1024+1287898))},
} }
for _, testfile := range tests { for _, testfile := range tests {
@ -2021,86 +2020,3 @@ func (fi wrappedFileInfo) Sys() interface{} {
func (fi wrappedFileInfo) Mode() os.FileMode { func (fi wrappedFileInfo) Mode() os.FileMode {
return fi.mode return fi.mode
} }
func TestMetadataChanged(t *testing.T) {
files := TestDir{
"testfile": TestFile{
Content: "foo bar test file",
},
}
tempdir, repo, cleanup := prepareTempdirRepoSrc(t, files)
defer cleanup()
back := fs.TestChdir(t, tempdir)
defer back()
// get metadata
fi := lstat(t, "testfile")
want, err := restic.NodeFromFileInfo("testfile", fi)
if err != nil {
t.Fatal(err)
}
fs := &StatFS{
FS: fs.Local{},
OverrideLstat: map[string]os.FileInfo{
"testfile": fi,
},
}
snapshotID, node2 := snapshot(t, repo, fs, restic.ID{}, "testfile")
// set some values so we can then compare the nodes
want.Content = node2.Content
want.Path = ""
want.ExtendedAttributes = nil
// make sure that metadata was recorded successfully
if !cmp.Equal(want, node2) {
t.Fatalf("metadata does not match:\n%v", cmp.Diff(want, node2))
}
// modify the mode
stat, ok := fi.Sys().(*syscall.Stat_t)
if ok {
// change a few values
stat.Mode = 0400
stat.Uid = 1234
stat.Gid = 1235
// wrap the os.FileInfo so we can return a modified stat_t
fi = wrappedFileInfo{
FileInfo: fi,
sys: stat,
mode: 0400,
}
fs.OverrideLstat["testfile"] = fi
} else {
// skip the test on this platform
t.Skipf("unable to modify os.FileInfo, Sys() returned %T", fi.Sys())
}
want, err = restic.NodeFromFileInfo("testfile", fi)
if err != nil {
t.Fatal(err)
}
// make another snapshot
snapshotID, node3 := snapshot(t, repo, fs, snapshotID, "testfile")
// set some values so we can then compare the nodes
want.Content = node2.Content
want.Path = ""
want.ExtendedAttributes = nil
// make sure that metadata was recorded successfully
if !cmp.Equal(want, node3) {
t.Fatalf("metadata does not match:\n%v", cmp.Diff(want, node2))
}
// make sure the content matches
TestEnsureFileContent(context.Background(), t, repo, "testfile", node3, files["testfile"].(TestFile))
checker.TestCheckRepo(t, repo)
}