mirror of
https://github.com/restic/restic.git
synced 2024-12-21 23:33:03 +00:00
use consistent alias for interal/test package
This commit is contained in:
parent
510f6f06b0
commit
ec2b79834a
9 changed files with 103 additions and 96 deletions
|
@ -38,6 +38,8 @@ linters:
|
||||||
# ensure that http response bodies are closed
|
# ensure that http response bodies are closed
|
||||||
- bodyclose
|
- bodyclose
|
||||||
|
|
||||||
|
- importas
|
||||||
|
|
||||||
issues:
|
issues:
|
||||||
# don't use the default exclude rules, this hides (among others) ignored
|
# don't use the default exclude rules, this hides (among others) ignored
|
||||||
# errors from Close() calls
|
# errors from Close() calls
|
||||||
|
@ -59,3 +61,9 @@ issues:
|
||||||
# revive: ignore unused parameters in tests
|
# revive: ignore unused parameters in tests
|
||||||
- path: (_test\.go|testing\.go|backend/.*/tests\.go)
|
- path: (_test\.go|testing\.go|backend/.*/tests\.go)
|
||||||
text: "unused-parameter:"
|
text: "unused-parameter:"
|
||||||
|
|
||||||
|
linters-settings:
|
||||||
|
importas:
|
||||||
|
alias:
|
||||||
|
- pkg: github.com/restic/restic/internal/test
|
||||||
|
alias: rtest
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
mrand "math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
@ -116,7 +116,7 @@ func TestRestore(t *testing.T) {
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
p := filepath.Join(env.testdata, fmt.Sprintf("foo/bar/testfile%v", i))
|
p := filepath.Join(env.testdata, fmt.Sprintf("foo/bar/testfile%v", i))
|
||||||
rtest.OK(t, os.MkdirAll(filepath.Dir(p), 0755))
|
rtest.OK(t, os.MkdirAll(filepath.Dir(p), 0755))
|
||||||
rtest.OK(t, appendRandomData(p, uint(mrand.Intn(2<<21))))
|
rtest.OK(t, appendRandomData(p, uint(rand.Intn(2<<21))))
|
||||||
}
|
}
|
||||||
|
|
||||||
opts := BackupOptions{}
|
opts := BackupOptions{}
|
||||||
|
|
|
@ -23,12 +23,12 @@ import (
|
||||||
"github.com/restic/restic/internal/fs"
|
"github.com/restic/restic/internal/fs"
|
||||||
"github.com/restic/restic/internal/repository"
|
"github.com/restic/restic/internal/repository"
|
||||||
"github.com/restic/restic/internal/restic"
|
"github.com/restic/restic/internal/restic"
|
||||||
restictest "github.com/restic/restic/internal/test"
|
rtest "github.com/restic/restic/internal/test"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
)
|
)
|
||||||
|
|
||||||
func prepareTempdirRepoSrc(t testing.TB, src TestDir) (string, restic.Repository) {
|
func prepareTempdirRepoSrc(t testing.TB, src TestDir) (string, restic.Repository) {
|
||||||
tempdir := restictest.TempDir(t)
|
tempdir := rtest.TempDir(t)
|
||||||
repo := repository.TestRepository(t)
|
repo := repository.TestRepository(t)
|
||||||
|
|
||||||
TestCreateFiles(t, tempdir, src)
|
TestCreateFiles(t, tempdir, src)
|
||||||
|
@ -133,7 +133,7 @@ func TestArchiverSaveFile(t *testing.T) {
|
||||||
var tests = []TestFile{
|
var tests = []TestFile{
|
||||||
{Content: ""},
|
{Content: ""},
|
||||||
{Content: "foo"},
|
{Content: "foo"},
|
||||||
{Content: string(restictest.Random(23, 12*1024*1024+1287898))},
|
{Content: string(rtest.Random(23, 12*1024*1024+1287898))},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testfile := range tests {
|
for _, testfile := range tests {
|
||||||
|
@ -166,7 +166,7 @@ func TestArchiverSaveFileReaderFS(t *testing.T) {
|
||||||
Data string
|
Data string
|
||||||
}{
|
}{
|
||||||
{Data: "foo"},
|
{Data: "foo"},
|
||||||
{Data: string(restictest.Random(23, 12*1024*1024+1287898))},
|
{Data: string(rtest.Random(23, 12*1024*1024+1287898))},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
@ -208,7 +208,7 @@ func TestArchiverSave(t *testing.T) {
|
||||||
var tests = []TestFile{
|
var tests = []TestFile{
|
||||||
{Content: ""},
|
{Content: ""},
|
||||||
{Content: "foo"},
|
{Content: "foo"},
|
||||||
{Content: string(restictest.Random(23, 12*1024*1024+1287898))},
|
{Content: string(rtest.Random(23, 12*1024*1024+1287898))},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testfile := range tests {
|
for _, testfile := range tests {
|
||||||
|
@ -277,7 +277,7 @@ func TestArchiverSaveReaderFS(t *testing.T) {
|
||||||
Data string
|
Data string
|
||||||
}{
|
}{
|
||||||
{Data: "foo"},
|
{Data: "foo"},
|
||||||
{Data: string(restictest.Random(23, 12*1024*1024+1287898))},
|
{Data: string(rtest.Random(23, 12*1024*1024+1287898))},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
@ -354,7 +354,7 @@ func TestArchiverSaveReaderFS(t *testing.T) {
|
||||||
func BenchmarkArchiverSaveFileSmall(b *testing.B) {
|
func BenchmarkArchiverSaveFileSmall(b *testing.B) {
|
||||||
const fileSize = 4 * 1024
|
const fileSize = 4 * 1024
|
||||||
d := TestDir{"file": TestFile{
|
d := TestDir{"file": TestFile{
|
||||||
Content: string(restictest.Random(23, fileSize)),
|
Content: string(rtest.Random(23, fileSize)),
|
||||||
}}
|
}}
|
||||||
|
|
||||||
b.SetBytes(fileSize)
|
b.SetBytes(fileSize)
|
||||||
|
@ -386,7 +386,7 @@ func BenchmarkArchiverSaveFileSmall(b *testing.B) {
|
||||||
func BenchmarkArchiverSaveFileLarge(b *testing.B) {
|
func BenchmarkArchiverSaveFileLarge(b *testing.B) {
|
||||||
const fileSize = 40*1024*1024 + 1287898
|
const fileSize = 40*1024*1024 + 1287898
|
||||||
d := TestDir{"file": TestFile{
|
d := TestDir{"file": TestFile{
|
||||||
Content: string(restictest.Random(23, fileSize)),
|
Content: string(rtest.Random(23, fileSize)),
|
||||||
}}
|
}}
|
||||||
|
|
||||||
b.SetBytes(fileSize)
|
b.SetBytes(fileSize)
|
||||||
|
@ -462,14 +462,14 @@ func appendToFile(t testing.TB, filename string, data []byte) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestArchiverSaveFileIncremental(t *testing.T) {
|
func TestArchiverSaveFileIncremental(t *testing.T) {
|
||||||
tempdir := restictest.TempDir(t)
|
tempdir := rtest.TempDir(t)
|
||||||
|
|
||||||
repo := &blobCountingRepo{
|
repo := &blobCountingRepo{
|
||||||
Repository: repository.TestRepository(t),
|
Repository: repository.TestRepository(t),
|
||||||
saved: make(map[restic.BlobHandle]uint),
|
saved: make(map[restic.BlobHandle]uint),
|
||||||
}
|
}
|
||||||
|
|
||||||
data := restictest.Random(23, 512*1024+887898)
|
data := rtest.Random(23, 512*1024+887898)
|
||||||
testfile := filepath.Join(tempdir, "testfile")
|
testfile := filepath.Join(tempdir, "testfile")
|
||||||
|
|
||||||
for i := 0; i < 3; i++ {
|
for i := 0; i < 3; i++ {
|
||||||
|
@ -512,12 +512,12 @@ func chmodTwice(t testing.TB, name string) {
|
||||||
// POSIX says that ctime is updated "even if the file status does not
|
// POSIX says that ctime is updated "even if the file status does not
|
||||||
// change", but let's make sure it does change, just in case.
|
// change", but let's make sure it does change, just in case.
|
||||||
err := os.Chmod(name, 0700)
|
err := os.Chmod(name, 0700)
|
||||||
restictest.OK(t, err)
|
rtest.OK(t, err)
|
||||||
|
|
||||||
sleep()
|
sleep()
|
||||||
|
|
||||||
err = os.Chmod(name, 0600)
|
err = os.Chmod(name, 0600)
|
||||||
restictest.OK(t, err)
|
rtest.OK(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func lstat(t testing.TB, name string) os.FileInfo {
|
func lstat(t testing.TB, name string) os.FileInfo {
|
||||||
|
@ -676,7 +676,7 @@ func TestFileChanged(t *testing.T) {
|
||||||
t.Skip("don't run test on Windows")
|
t.Skip("don't run test on Windows")
|
||||||
}
|
}
|
||||||
|
|
||||||
tempdir := restictest.TempDir(t)
|
tempdir := rtest.TempDir(t)
|
||||||
|
|
||||||
filename := filepath.Join(tempdir, "file")
|
filename := filepath.Join(tempdir, "file")
|
||||||
content := defaultContent
|
content := defaultContent
|
||||||
|
@ -712,7 +712,7 @@ func TestFileChanged(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFilChangedSpecialCases(t *testing.T) {
|
func TestFilChangedSpecialCases(t *testing.T) {
|
||||||
tempdir := restictest.TempDir(t)
|
tempdir := rtest.TempDir(t)
|
||||||
|
|
||||||
filename := filepath.Join(tempdir, "file")
|
filename := filepath.Join(tempdir, "file")
|
||||||
content := []byte("foobar")
|
content := []byte("foobar")
|
||||||
|
@ -746,12 +746,12 @@ func TestArchiverSaveDir(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
src: TestDir{
|
src: TestDir{
|
||||||
"targetfile": TestFile{Content: string(restictest.Random(888, 2*1024*1024+5000))},
|
"targetfile": TestFile{Content: string(rtest.Random(888, 2*1024*1024+5000))},
|
||||||
},
|
},
|
||||||
target: ".",
|
target: ".",
|
||||||
want: TestDir{
|
want: TestDir{
|
||||||
"targetdir": TestDir{
|
"targetdir": TestDir{
|
||||||
"targetfile": TestFile{Content: string(restictest.Random(888, 2*1024*1024+5000))},
|
"targetfile": TestFile{Content: string(rtest.Random(888, 2*1024*1024+5000))},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -761,8 +761,8 @@ func TestArchiverSaveDir(t *testing.T) {
|
||||||
"foo": TestFile{Content: "foo"},
|
"foo": TestFile{Content: "foo"},
|
||||||
"emptyfile": TestFile{Content: ""},
|
"emptyfile": TestFile{Content: ""},
|
||||||
"bar": TestFile{Content: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"},
|
"bar": TestFile{Content: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"},
|
||||||
"largefile": TestFile{Content: string(restictest.Random(888, 2*1024*1024+5000))},
|
"largefile": TestFile{Content: string(rtest.Random(888, 2*1024*1024+5000))},
|
||||||
"largerfile": TestFile{Content: string(restictest.Random(234, 5*1024*1024+5000))},
|
"largerfile": TestFile{Content: string(rtest.Random(234, 5*1024*1024+5000))},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
target: "targetdir",
|
target: "targetdir",
|
||||||
|
@ -841,7 +841,7 @@ func TestArchiverSaveDir(t *testing.T) {
|
||||||
chdir = filepath.Join(chdir, test.chdir)
|
chdir = filepath.Join(chdir, test.chdir)
|
||||||
}
|
}
|
||||||
|
|
||||||
back := restictest.Chdir(t, chdir)
|
back := rtest.Chdir(t, chdir)
|
||||||
defer back()
|
defer back()
|
||||||
|
|
||||||
fi, err := fs.Lstat(test.target)
|
fi, err := fs.Lstat(test.target)
|
||||||
|
@ -899,7 +899,7 @@ func TestArchiverSaveDir(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestArchiverSaveDirIncremental(t *testing.T) {
|
func TestArchiverSaveDirIncremental(t *testing.T) {
|
||||||
tempdir := restictest.TempDir(t)
|
tempdir := rtest.TempDir(t)
|
||||||
|
|
||||||
repo := &blobCountingRepo{
|
repo := &blobCountingRepo{
|
||||||
Repository: repository.TestRepository(t),
|
Repository: repository.TestRepository(t),
|
||||||
|
@ -989,7 +989,7 @@ func TestArchiverSaveDirIncremental(t *testing.T) {
|
||||||
func bothZeroOrNeither(tb testing.TB, exp, act uint64) {
|
func bothZeroOrNeither(tb testing.TB, exp, act uint64) {
|
||||||
tb.Helper()
|
tb.Helper()
|
||||||
if (exp == 0 && act != 0) || (exp != 0 && act == 0) {
|
if (exp == 0 && act != 0) || (exp != 0 && act == 0) {
|
||||||
restictest.Equals(tb, exp, act)
|
rtest.Equals(tb, exp, act)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1113,7 +1113,7 @@ func TestArchiverSaveTree(t *testing.T) {
|
||||||
arch.runWorkers(ctx, wg)
|
arch.runWorkers(ctx, wg)
|
||||||
arch.summary = &Summary{}
|
arch.summary = &Summary{}
|
||||||
|
|
||||||
back := restictest.Chdir(t, tempdir)
|
back := rtest.Chdir(t, tempdir)
|
||||||
defer back()
|
defer back()
|
||||||
|
|
||||||
if test.prepare != nil {
|
if test.prepare != nil {
|
||||||
|
@ -1158,9 +1158,9 @@ func TestArchiverSaveTree(t *testing.T) {
|
||||||
bothZeroOrNeither(t, test.stat.DataSize, stat.DataSize)
|
bothZeroOrNeither(t, test.stat.DataSize, stat.DataSize)
|
||||||
bothZeroOrNeither(t, test.stat.DataSizeInRepo, stat.DataSizeInRepo)
|
bothZeroOrNeither(t, test.stat.DataSizeInRepo, stat.DataSizeInRepo)
|
||||||
bothZeroOrNeither(t, test.stat.TreeSizeInRepo, stat.TreeSizeInRepo)
|
bothZeroOrNeither(t, test.stat.TreeSizeInRepo, stat.TreeSizeInRepo)
|
||||||
restictest.Equals(t, test.stat.ProcessedBytes, stat.ProcessedBytes)
|
rtest.Equals(t, test.stat.ProcessedBytes, stat.ProcessedBytes)
|
||||||
restictest.Equals(t, test.stat.Files, stat.Files)
|
rtest.Equals(t, test.stat.Files, stat.Files)
|
||||||
restictest.Equals(t, test.stat.Dirs, stat.Dirs)
|
rtest.Equals(t, test.stat.Dirs, stat.Dirs)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1408,7 +1408,7 @@ func TestArchiverSnapshot(t *testing.T) {
|
||||||
chdir = filepath.Join(chdir, filepath.FromSlash(test.chdir))
|
chdir = filepath.Join(chdir, filepath.FromSlash(test.chdir))
|
||||||
}
|
}
|
||||||
|
|
||||||
back := restictest.Chdir(t, chdir)
|
back := rtest.Chdir(t, chdir)
|
||||||
defer back()
|
defer back()
|
||||||
|
|
||||||
var targets []string
|
var targets []string
|
||||||
|
@ -1561,7 +1561,7 @@ func TestArchiverSnapshotSelect(t *testing.T) {
|
||||||
arch := New(repo, fs.Track{FS: fs.Local{}}, Options{})
|
arch := New(repo, fs.Track{FS: fs.Local{}}, Options{})
|
||||||
arch.Select = test.selFn
|
arch.Select = test.selFn
|
||||||
|
|
||||||
back := restictest.Chdir(t, tempdir)
|
back := rtest.Chdir(t, tempdir)
|
||||||
defer back()
|
defer back()
|
||||||
|
|
||||||
targets := []string{"."}
|
targets := []string{"."}
|
||||||
|
@ -1639,14 +1639,14 @@ func (f MockFile) Read(p []byte) (int, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkSnapshotStats(t *testing.T, sn *restic.Snapshot, stat Summary) {
|
func checkSnapshotStats(t *testing.T, sn *restic.Snapshot, stat Summary) {
|
||||||
restictest.Equals(t, stat.Files.New, sn.Summary.FilesNew)
|
rtest.Equals(t, stat.Files.New, sn.Summary.FilesNew)
|
||||||
restictest.Equals(t, stat.Files.Changed, sn.Summary.FilesChanged)
|
rtest.Equals(t, stat.Files.Changed, sn.Summary.FilesChanged)
|
||||||
restictest.Equals(t, stat.Files.Unchanged, sn.Summary.FilesUnmodified)
|
rtest.Equals(t, stat.Files.Unchanged, sn.Summary.FilesUnmodified)
|
||||||
restictest.Equals(t, stat.Dirs.New, sn.Summary.DirsNew)
|
rtest.Equals(t, stat.Dirs.New, sn.Summary.DirsNew)
|
||||||
restictest.Equals(t, stat.Dirs.Changed, sn.Summary.DirsChanged)
|
rtest.Equals(t, stat.Dirs.Changed, sn.Summary.DirsChanged)
|
||||||
restictest.Equals(t, stat.Dirs.Unchanged, sn.Summary.DirsUnmodified)
|
rtest.Equals(t, stat.Dirs.Unchanged, sn.Summary.DirsUnmodified)
|
||||||
restictest.Equals(t, stat.ProcessedBytes, sn.Summary.TotalBytesProcessed)
|
rtest.Equals(t, stat.ProcessedBytes, sn.Summary.TotalBytesProcessed)
|
||||||
restictest.Equals(t, stat.Files.New+stat.Files.Changed+stat.Files.Unchanged, sn.Summary.TotalFilesProcessed)
|
rtest.Equals(t, stat.Files.New+stat.Files.Changed+stat.Files.Unchanged, sn.Summary.TotalFilesProcessed)
|
||||||
bothZeroOrNeither(t, uint64(stat.DataBlobs), uint64(sn.Summary.DataBlobs))
|
bothZeroOrNeither(t, uint64(stat.DataBlobs), uint64(sn.Summary.DataBlobs))
|
||||||
bothZeroOrNeither(t, uint64(stat.TreeBlobs), uint64(sn.Summary.TreeBlobs))
|
bothZeroOrNeither(t, uint64(stat.TreeBlobs), uint64(sn.Summary.TreeBlobs))
|
||||||
bothZeroOrNeither(t, uint64(stat.DataSize+stat.TreeSize), uint64(sn.Summary.DataAdded))
|
bothZeroOrNeither(t, uint64(stat.DataSize+stat.TreeSize), uint64(sn.Summary.DataAdded))
|
||||||
|
@ -1662,7 +1662,7 @@ func TestArchiverParent(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
src: TestDir{
|
src: TestDir{
|
||||||
"targetfile": TestFile{Content: string(restictest.Random(888, 2*1024*1024+5000))},
|
"targetfile": TestFile{Content: string(rtest.Random(888, 2*1024*1024+5000))},
|
||||||
},
|
},
|
||||||
statInitial: Summary{
|
statInitial: Summary{
|
||||||
Files: ChangeStats{1, 0, 0},
|
Files: ChangeStats{1, 0, 0},
|
||||||
|
@ -1679,8 +1679,8 @@ func TestArchiverParent(t *testing.T) {
|
||||||
{
|
{
|
||||||
src: TestDir{
|
src: TestDir{
|
||||||
"targetDir": TestDir{
|
"targetDir": TestDir{
|
||||||
"targetfile": TestFile{Content: string(restictest.Random(888, 1234))},
|
"targetfile": TestFile{Content: string(rtest.Random(888, 1234))},
|
||||||
"targetfile2": TestFile{Content: string(restictest.Random(888, 1235))},
|
"targetfile2": TestFile{Content: string(rtest.Random(888, 1235))},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
statInitial: Summary{
|
statInitial: Summary{
|
||||||
|
@ -1698,9 +1698,9 @@ func TestArchiverParent(t *testing.T) {
|
||||||
{
|
{
|
||||||
src: TestDir{
|
src: TestDir{
|
||||||
"targetDir": TestDir{
|
"targetDir": TestDir{
|
||||||
"targetfile": TestFile{Content: string(restictest.Random(888, 1234))},
|
"targetfile": TestFile{Content: string(rtest.Random(888, 1234))},
|
||||||
},
|
},
|
||||||
"targetfile2": TestFile{Content: string(restictest.Random(888, 1235))},
|
"targetfile2": TestFile{Content: string(rtest.Random(888, 1235))},
|
||||||
},
|
},
|
||||||
modify: func(path string) {
|
modify: func(path string) {
|
||||||
remove(t, filepath.Join(path, "targetDir", "targetfile"))
|
remove(t, filepath.Join(path, "targetDir", "targetfile"))
|
||||||
|
@ -1735,7 +1735,7 @@ func TestArchiverParent(t *testing.T) {
|
||||||
|
|
||||||
arch := New(repo, testFS, Options{})
|
arch := New(repo, testFS, Options{})
|
||||||
|
|
||||||
back := restictest.Chdir(t, tempdir)
|
back := rtest.Chdir(t, tempdir)
|
||||||
defer back()
|
defer back()
|
||||||
|
|
||||||
firstSnapshot, firstSnapshotID, summary, err := arch.Snapshot(ctx, []string{"."}, SnapshotOptions{Time: time.Now()})
|
firstSnapshot, firstSnapshotID, summary, err := arch.Snapshot(ctx, []string{"."}, SnapshotOptions{Time: time.Now()})
|
||||||
|
@ -1763,9 +1763,9 @@ func TestArchiverParent(t *testing.T) {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
restictest.Equals(t, test.statInitial.Files, summary.Files)
|
rtest.Equals(t, test.statInitial.Files, summary.Files)
|
||||||
restictest.Equals(t, test.statInitial.Dirs, summary.Dirs)
|
rtest.Equals(t, test.statInitial.Dirs, summary.Dirs)
|
||||||
restictest.Equals(t, test.statInitial.ProcessedBytes, summary.ProcessedBytes)
|
rtest.Equals(t, test.statInitial.ProcessedBytes, summary.ProcessedBytes)
|
||||||
checkSnapshotStats(t, firstSnapshot, test.statInitial)
|
checkSnapshotStats(t, firstSnapshot, test.statInitial)
|
||||||
|
|
||||||
if test.modify != nil {
|
if test.modify != nil {
|
||||||
|
@ -1784,11 +1784,11 @@ func TestArchiverParent(t *testing.T) {
|
||||||
|
|
||||||
if test.modify == nil {
|
if test.modify == nil {
|
||||||
// check that no files were read this time
|
// check that no files were read this time
|
||||||
restictest.Equals(t, map[string]int{}, testFS.bytesRead)
|
rtest.Equals(t, map[string]int{}, testFS.bytesRead)
|
||||||
}
|
}
|
||||||
restictest.Equals(t, test.statSecond.Files, summary.Files)
|
rtest.Equals(t, test.statSecond.Files, summary.Files)
|
||||||
restictest.Equals(t, test.statSecond.Dirs, summary.Dirs)
|
rtest.Equals(t, test.statSecond.Dirs, summary.Dirs)
|
||||||
restictest.Equals(t, test.statSecond.ProcessedBytes, summary.ProcessedBytes)
|
rtest.Equals(t, test.statSecond.ProcessedBytes, summary.ProcessedBytes)
|
||||||
checkSnapshotStats(t, secondSnapshot, test.statSecond)
|
checkSnapshotStats(t, secondSnapshot, test.statSecond)
|
||||||
|
|
||||||
t.Logf("second backup saved as %v", secondSnapshotID.Str())
|
t.Logf("second backup saved as %v", secondSnapshotID.Str())
|
||||||
|
@ -1894,7 +1894,7 @@ func TestArchiverErrorReporting(t *testing.T) {
|
||||||
|
|
||||||
tempdir, repo := prepareTempdirRepoSrc(t, test.src)
|
tempdir, repo := prepareTempdirRepoSrc(t, test.src)
|
||||||
|
|
||||||
back := restictest.Chdir(t, tempdir)
|
back := rtest.Chdir(t, tempdir)
|
||||||
defer back()
|
defer back()
|
||||||
|
|
||||||
if test.prepare != nil {
|
if test.prepare != nil {
|
||||||
|
@ -1964,7 +1964,7 @@ func TestArchiverContextCanceled(t *testing.T) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
cancel()
|
cancel()
|
||||||
|
|
||||||
tempdir := restictest.TempDir(t)
|
tempdir := rtest.TempDir(t)
|
||||||
TestCreateFiles(t, tempdir, TestDir{
|
TestCreateFiles(t, tempdir, TestDir{
|
||||||
"targetfile": TestFile{Content: "foobar"},
|
"targetfile": TestFile{Content: "foobar"},
|
||||||
})
|
})
|
||||||
|
@ -1972,7 +1972,7 @@ func TestArchiverContextCanceled(t *testing.T) {
|
||||||
// Ensure that the archiver itself reports the canceled context and not just the backend
|
// Ensure that the archiver itself reports the canceled context and not just the backend
|
||||||
repo := repository.TestRepositoryWithBackend(t, &noCancelBackend{mem.New()}, 0, repository.Options{})
|
repo := repository.TestRepositoryWithBackend(t, &noCancelBackend{mem.New()}, 0, repository.Options{})
|
||||||
|
|
||||||
back := restictest.Chdir(t, tempdir)
|
back := rtest.Chdir(t, tempdir)
|
||||||
defer back()
|
defer back()
|
||||||
|
|
||||||
arch := New(repo, fs.Track{FS: fs.Local{}}, Options{})
|
arch := New(repo, fs.Track{FS: fs.Local{}}, Options{})
|
||||||
|
@ -2058,16 +2058,16 @@ func TestArchiverAbortEarlyOnError(t *testing.T) {
|
||||||
{
|
{
|
||||||
src: TestDir{
|
src: TestDir{
|
||||||
"dir": TestDir{
|
"dir": TestDir{
|
||||||
"file0": TestFile{Content: string(restictest.Random(0, 1024))},
|
"file0": TestFile{Content: string(rtest.Random(0, 1024))},
|
||||||
"file1": TestFile{Content: string(restictest.Random(1, 1024))},
|
"file1": TestFile{Content: string(rtest.Random(1, 1024))},
|
||||||
"file2": TestFile{Content: string(restictest.Random(2, 1024))},
|
"file2": TestFile{Content: string(rtest.Random(2, 1024))},
|
||||||
"file3": TestFile{Content: string(restictest.Random(3, 1024))},
|
"file3": TestFile{Content: string(rtest.Random(3, 1024))},
|
||||||
"file4": TestFile{Content: string(restictest.Random(4, 1024))},
|
"file4": TestFile{Content: string(rtest.Random(4, 1024))},
|
||||||
"file5": TestFile{Content: string(restictest.Random(5, 1024))},
|
"file5": TestFile{Content: string(rtest.Random(5, 1024))},
|
||||||
"file6": TestFile{Content: string(restictest.Random(6, 1024))},
|
"file6": TestFile{Content: string(rtest.Random(6, 1024))},
|
||||||
"file7": TestFile{Content: string(restictest.Random(7, 1024))},
|
"file7": TestFile{Content: string(rtest.Random(7, 1024))},
|
||||||
"file8": TestFile{Content: string(restictest.Random(8, 1024))},
|
"file8": TestFile{Content: string(rtest.Random(8, 1024))},
|
||||||
"file9": TestFile{Content: string(restictest.Random(9, 1024))},
|
"file9": TestFile{Content: string(rtest.Random(9, 1024))},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
wantOpen: map[string]uint{
|
wantOpen: map[string]uint{
|
||||||
|
@ -2092,7 +2092,7 @@ func TestArchiverAbortEarlyOnError(t *testing.T) {
|
||||||
|
|
||||||
tempdir, repo := prepareTempdirRepoSrc(t, test.src)
|
tempdir, repo := prepareTempdirRepoSrc(t, test.src)
|
||||||
|
|
||||||
back := restictest.Chdir(t, tempdir)
|
back := rtest.Chdir(t, tempdir)
|
||||||
defer back()
|
defer back()
|
||||||
|
|
||||||
testFS := &TrackFS{
|
testFS := &TrackFS{
|
||||||
|
@ -2225,7 +2225,7 @@ func TestMetadataChanged(t *testing.T) {
|
||||||
|
|
||||||
tempdir, repo := prepareTempdirRepoSrc(t, files)
|
tempdir, repo := prepareTempdirRepoSrc(t, files)
|
||||||
|
|
||||||
back := restictest.Chdir(t, tempdir)
|
back := rtest.Chdir(t, tempdir)
|
||||||
defer back()
|
defer back()
|
||||||
|
|
||||||
// get metadata
|
// get metadata
|
||||||
|
@ -2300,7 +2300,7 @@ func TestRacyFileSwap(t *testing.T) {
|
||||||
|
|
||||||
tempdir, repo := prepareTempdirRepoSrc(t, files)
|
tempdir, repo := prepareTempdirRepoSrc(t, files)
|
||||||
|
|
||||||
back := restictest.Chdir(t, tempdir)
|
back := rtest.Chdir(t, tempdir)
|
||||||
defer back()
|
defer back()
|
||||||
|
|
||||||
// get metadata of current folder
|
// get metadata of current folder
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"github.com/restic/restic/internal/feature"
|
"github.com/restic/restic/internal/feature"
|
||||||
"github.com/restic/restic/internal/fs"
|
"github.com/restic/restic/internal/fs"
|
||||||
"github.com/restic/restic/internal/restic"
|
"github.com/restic/restic/internal/restic"
|
||||||
restictest "github.com/restic/restic/internal/test"
|
rtest "github.com/restic/restic/internal/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
type wrappedFileInfo struct {
|
type wrappedFileInfo struct {
|
||||||
|
@ -49,7 +49,7 @@ func wrapFileInfo(fi os.FileInfo) os.FileInfo {
|
||||||
func statAndSnapshot(t *testing.T, repo restic.Repository, name string) (*restic.Node, *restic.Node) {
|
func statAndSnapshot(t *testing.T, repo restic.Repository, name string) (*restic.Node, *restic.Node) {
|
||||||
fi := lstat(t, name)
|
fi := lstat(t, name)
|
||||||
want, err := restic.NodeFromFileInfo(name, fi)
|
want, err := restic.NodeFromFileInfo(name, fi)
|
||||||
restictest.OK(t, err)
|
rtest.OK(t, err)
|
||||||
|
|
||||||
_, node := snapshot(t, repo, fs.Local{}, nil, name)
|
_, node := snapshot(t, repo, fs.Local{}, nil, name)
|
||||||
return want, node
|
return want, node
|
||||||
|
@ -73,17 +73,17 @@ func TestHardlinkMetadata(t *testing.T) {
|
||||||
|
|
||||||
tempdir, repo := prepareTempdirRepoSrc(t, files)
|
tempdir, repo := prepareTempdirRepoSrc(t, files)
|
||||||
|
|
||||||
back := restictest.Chdir(t, tempdir)
|
back := rtest.Chdir(t, tempdir)
|
||||||
defer back()
|
defer back()
|
||||||
|
|
||||||
want, node := statAndSnapshot(t, repo, "testlink")
|
want, node := statAndSnapshot(t, repo, "testlink")
|
||||||
restictest.Assert(t, node.DeviceID == want.DeviceID, "device id mismatch expected %v got %v", want.DeviceID, node.DeviceID)
|
rtest.Assert(t, node.DeviceID == want.DeviceID, "device id mismatch expected %v got %v", want.DeviceID, node.DeviceID)
|
||||||
restictest.Assert(t, node.Links == want.Links, "link count mismatch expected %v got %v", want.Links, node.Links)
|
rtest.Assert(t, node.Links == want.Links, "link count mismatch expected %v got %v", want.Links, node.Links)
|
||||||
restictest.Assert(t, node.Inode == want.Inode, "inode mismatch expected %v got %v", want.Inode, node.Inode)
|
rtest.Assert(t, node.Inode == want.Inode, "inode mismatch expected %v got %v", want.Inode, node.Inode)
|
||||||
|
|
||||||
_, node = statAndSnapshot(t, repo, "testfile")
|
_, node = statAndSnapshot(t, repo, "testfile")
|
||||||
restictest.Assert(t, node.DeviceID == 0, "device id mismatch for testfile expected %v got %v", 0, node.DeviceID)
|
rtest.Assert(t, node.DeviceID == 0, "device id mismatch for testfile expected %v got %v", 0, node.DeviceID)
|
||||||
|
|
||||||
_, node = statAndSnapshot(t, repo, "testdir")
|
_, node = statAndSnapshot(t, repo, "testdir")
|
||||||
restictest.Assert(t, node.DeviceID == 0, "device id mismatch for testdir expected %v got %v", 0, node.DeviceID)
|
rtest.Assert(t, node.DeviceID == 0, "device id mismatch for testdir expected %v got %v", 0, node.DeviceID)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
"github.com/restic/restic/internal/fs"
|
"github.com/restic/restic/internal/fs"
|
||||||
restictest "github.com/restic/restic/internal/test"
|
rtest "github.com/restic/restic/internal/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestScanner(t *testing.T) {
|
func TestScanner(t *testing.T) {
|
||||||
|
@ -81,10 +81,10 @@ func TestScanner(t *testing.T) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
tempdir := restictest.TempDir(t)
|
tempdir := rtest.TempDir(t)
|
||||||
TestCreateFiles(t, tempdir, test.src)
|
TestCreateFiles(t, tempdir, test.src)
|
||||||
|
|
||||||
back := restictest.Chdir(t, tempdir)
|
back := rtest.Chdir(t, tempdir)
|
||||||
defer back()
|
defer back()
|
||||||
|
|
||||||
cur, err := os.Getwd()
|
cur, err := os.Getwd()
|
||||||
|
@ -216,10 +216,10 @@ func TestScannerError(t *testing.T) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
tempdir := restictest.TempDir(t)
|
tempdir := rtest.TempDir(t)
|
||||||
TestCreateFiles(t, tempdir, test.src)
|
TestCreateFiles(t, tempdir, test.src)
|
||||||
|
|
||||||
back := restictest.Chdir(t, tempdir)
|
back := rtest.Chdir(t, tempdir)
|
||||||
defer back()
|
defer back()
|
||||||
|
|
||||||
cur, err := os.Getwd()
|
cur, err := os.Getwd()
|
||||||
|
@ -288,10 +288,10 @@ func TestScannerCancel(t *testing.T) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
tempdir := restictest.TempDir(t)
|
tempdir := rtest.TempDir(t)
|
||||||
TestCreateFiles(t, tempdir, src)
|
TestCreateFiles(t, tempdir, src)
|
||||||
|
|
||||||
back := restictest.Chdir(t, tempdir)
|
back := rtest.Chdir(t, tempdir)
|
||||||
defer back()
|
defer back()
|
||||||
|
|
||||||
cur, err := os.Getwd()
|
cur, err := os.Getwd()
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
"github.com/restic/restic/internal/fs"
|
"github.com/restic/restic/internal/fs"
|
||||||
"github.com/restic/restic/internal/repository"
|
"github.com/restic/restic/internal/repository"
|
||||||
restictest "github.com/restic/restic/internal/test"
|
rtest "github.com/restic/restic/internal/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MockT passes through all logging functions from T, but catches Fail(),
|
// MockT passes through all logging functions from T, but catches Fail(),
|
||||||
|
@ -101,7 +101,7 @@ func TestTestCreateFiles(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, test := range tests {
|
for i, test := range tests {
|
||||||
tempdir := restictest.TempDir(t)
|
tempdir := rtest.TempDir(t)
|
||||||
|
|
||||||
t.Run("", func(t *testing.T) {
|
t.Run("", func(t *testing.T) {
|
||||||
tempdir := filepath.Join(tempdir, fmt.Sprintf("test-%d", i))
|
tempdir := filepath.Join(tempdir, fmt.Sprintf("test-%d", i))
|
||||||
|
@ -191,7 +191,7 @@ func TestTestWalkFiles(t *testing.T) {
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run("", func(t *testing.T) {
|
t.Run("", func(t *testing.T) {
|
||||||
tempdir := restictest.TempDir(t)
|
tempdir := rtest.TempDir(t)
|
||||||
|
|
||||||
got := make(map[string]string)
|
got := make(map[string]string)
|
||||||
|
|
||||||
|
@ -321,7 +321,7 @@ func TestTestEnsureFiles(t *testing.T) {
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run("", func(t *testing.T) {
|
t.Run("", func(t *testing.T) {
|
||||||
tempdir := restictest.TempDir(t)
|
tempdir := rtest.TempDir(t)
|
||||||
createFilesAt(t, tempdir, test.files)
|
createFilesAt(t, tempdir, test.files)
|
||||||
|
|
||||||
subtestT := testing.TB(t)
|
subtestT := testing.TB(t)
|
||||||
|
@ -452,7 +452,7 @@ func TestTestEnsureSnapshot(t *testing.T) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
tempdir := restictest.TempDir(t)
|
tempdir := rtest.TempDir(t)
|
||||||
|
|
||||||
targetDir := filepath.Join(tempdir, "target")
|
targetDir := filepath.Join(tempdir, "target")
|
||||||
err := fs.Mkdir(targetDir, 0700)
|
err := fs.Mkdir(targetDir, 0700)
|
||||||
|
@ -462,7 +462,7 @@ func TestTestEnsureSnapshot(t *testing.T) {
|
||||||
|
|
||||||
createFilesAt(t, targetDir, test.files)
|
createFilesAt(t, targetDir, test.files)
|
||||||
|
|
||||||
back := restictest.Chdir(t, tempdir)
|
back := rtest.Chdir(t, tempdir)
|
||||||
defer back()
|
defer back()
|
||||||
|
|
||||||
repo := repository.TestRepository(t)
|
repo := repository.TestRepository(t)
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
"github.com/restic/restic/internal/fs"
|
"github.com/restic/restic/internal/fs"
|
||||||
restictest "github.com/restic/restic/internal/test"
|
rtest "github.com/restic/restic/internal/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
// debug.Log requires Tree.String.
|
// debug.Log requires Tree.String.
|
||||||
|
@ -439,10 +439,10 @@ func TestTree(t *testing.T) {
|
||||||
t.Skip("skip test on unix")
|
t.Skip("skip test on unix")
|
||||||
}
|
}
|
||||||
|
|
||||||
tempdir := restictest.TempDir(t)
|
tempdir := rtest.TempDir(t)
|
||||||
TestCreateFiles(t, tempdir, test.src)
|
TestCreateFiles(t, tempdir, test.src)
|
||||||
|
|
||||||
back := restictest.Chdir(t, tempdir)
|
back := rtest.Chdir(t, tempdir)
|
||||||
defer back()
|
defer back()
|
||||||
|
|
||||||
tree, err := NewTree(fs.Local{}, test.targets)
|
tree, err := NewTree(fs.Local{}, test.targets)
|
||||||
|
|
|
@ -5,11 +5,11 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
restictest "github.com/restic/restic/internal/test"
|
rtest "github.com/restic/restic/internal/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestExtendedStat(t *testing.T) {
|
func TestExtendedStat(t *testing.T) {
|
||||||
tempdir := restictest.TempDir(t)
|
tempdir := rtest.TempDir(t)
|
||||||
filename := filepath.Join(tempdir, "file")
|
filename := filepath.Join(tempdir, "file")
|
||||||
err := os.WriteFile(filename, []byte("foobar"), 0640)
|
err := os.WriteFile(filename, []byte("foobar"), 0640)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -12,8 +13,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/restic/restic/internal/errors"
|
"github.com/restic/restic/internal/errors"
|
||||||
|
|
||||||
mrand "math/rand"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Assert fails the test if the condition is false.
|
// Assert fails the test if the condition is false.
|
||||||
|
@ -71,7 +70,7 @@ func Equals(tb testing.TB, exp, act interface{}, msgs ...string) {
|
||||||
func Random(seed, count int) []byte {
|
func Random(seed, count int) []byte {
|
||||||
p := make([]byte, count)
|
p := make([]byte, count)
|
||||||
|
|
||||||
rnd := mrand.New(mrand.NewSource(int64(seed)))
|
rnd := rand.New(rand.NewSource(int64(seed)))
|
||||||
|
|
||||||
for i := 0; i < len(p); i += 8 {
|
for i := 0; i < len(p); i += 8 {
|
||||||
val := rnd.Int63()
|
val := rnd.Int63()
|
||||||
|
|
Loading…
Reference in a new issue