mirror of
https://github.com/restic/restic.git
synced 2025-08-12 17:07:40 +00:00
Merge pull request #1312 from hgfischer/issue-1119
nit: please remove dot imports #1119
This commit is contained in:
@@ -15,7 +15,7 @@ import (
|
||||
"github.com/restic/restic/internal/crypto"
|
||||
"github.com/restic/restic/internal/repository"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
. "github.com/restic/restic/internal/test"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
|
||||
"github.com/restic/restic/internal/errors"
|
||||
|
||||
@@ -40,14 +40,14 @@ func benchmarkChunkEncrypt(b testing.TB, buf, buf2 []byte, rd Rdr, key *crypto.K
|
||||
break
|
||||
}
|
||||
|
||||
OK(b, err)
|
||||
rtest.OK(b, err)
|
||||
|
||||
// reduce length of buf
|
||||
Assert(b, uint(len(chunk.Data)) == chunk.Length,
|
||||
rtest.Assert(b, uint(len(chunk.Data)) == chunk.Length,
|
||||
"invalid length: got %d, expected %d", len(chunk.Data), chunk.Length)
|
||||
|
||||
_, err = key.Encrypt(buf2, chunk.Data)
|
||||
OK(b, err)
|
||||
rtest.OK(b, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ func BenchmarkChunkEncrypt(b *testing.B) {
|
||||
repo, cleanup := repository.TestRepository(b)
|
||||
defer cleanup()
|
||||
|
||||
data := Random(23, 10<<20) // 10MiB
|
||||
data := rtest.Random(23, 10<<20) // 10MiB
|
||||
rd := bytes.NewReader(data)
|
||||
|
||||
buf := make([]byte, chunker.MaxSize)
|
||||
@@ -87,7 +87,7 @@ func BenchmarkChunkEncryptParallel(b *testing.B) {
|
||||
repo, cleanup := repository.TestRepository(b)
|
||||
defer cleanup()
|
||||
|
||||
data := Random(23, 10<<20) // 10MiB
|
||||
data := rtest.Random(23, 10<<20) // 10MiB
|
||||
|
||||
buf := make([]byte, chunker.MaxSize)
|
||||
|
||||
@@ -108,14 +108,14 @@ func archiveDirectory(b testing.TB) {
|
||||
|
||||
arch := archiver.New(repo)
|
||||
|
||||
_, id, err := arch.Snapshot(context.TODO(), nil, []string{BenchArchiveDirectory}, nil, "localhost", nil, time.Now())
|
||||
OK(b, err)
|
||||
_, id, err := arch.Snapshot(context.TODO(), nil, []string{rtest.BenchArchiveDirectory}, nil, "localhost", nil, time.Now())
|
||||
rtest.OK(b, err)
|
||||
|
||||
b.Logf("snapshot archived as %v", id)
|
||||
}
|
||||
|
||||
func TestArchiveDirectory(t *testing.T) {
|
||||
if BenchArchiveDirectory == "" {
|
||||
if rtest.BenchArchiveDirectory == "" {
|
||||
t.Skip("benchdir not set, skipping TestArchiveDirectory")
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ func TestArchiveDirectory(t *testing.T) {
|
||||
}
|
||||
|
||||
func BenchmarkArchiveDirectory(b *testing.B) {
|
||||
if BenchArchiveDirectory == "" {
|
||||
if rtest.BenchArchiveDirectory == "" {
|
||||
b.Skip("benchdir not set, skipping BenchmarkArchiveDirectory")
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ func archiveWithDedup(t testing.TB) {
|
||||
repo, cleanup := repository.TestRepository(t)
|
||||
defer cleanup()
|
||||
|
||||
if BenchArchiveDirectory == "" {
|
||||
if rtest.BenchArchiveDirectory == "" {
|
||||
t.Skip("benchdir not set, skipping TestArchiverDedup")
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ func archiveWithDedup(t testing.TB) {
|
||||
}
|
||||
|
||||
// archive a few files
|
||||
sn := archiver.TestSnapshot(t, repo, BenchArchiveDirectory, nil)
|
||||
sn := archiver.TestSnapshot(t, repo, rtest.BenchArchiveDirectory, nil)
|
||||
t.Logf("archived snapshot %v", sn.ID().Str())
|
||||
|
||||
// get archive stats
|
||||
@@ -166,7 +166,7 @@ func archiveWithDedup(t testing.TB) {
|
||||
cnt.before.packs, cnt.before.dataBlobs, cnt.before.treeBlobs)
|
||||
|
||||
// archive the same files again, without parent snapshot
|
||||
sn2 := archiver.TestSnapshot(t, repo, BenchArchiveDirectory, nil)
|
||||
sn2 := archiver.TestSnapshot(t, repo, rtest.BenchArchiveDirectory, nil)
|
||||
t.Logf("archived snapshot %v", sn2.ID().Str())
|
||||
|
||||
// get archive stats again
|
||||
@@ -183,7 +183,7 @@ func archiveWithDedup(t testing.TB) {
|
||||
}
|
||||
|
||||
// archive the same files again, with a parent snapshot
|
||||
sn3 := archiver.TestSnapshot(t, repo, BenchArchiveDirectory, sn2.ID())
|
||||
sn3 := archiver.TestSnapshot(t, repo, rtest.BenchArchiveDirectory, sn2.ID())
|
||||
t.Logf("archived snapshot %v, parent %v", sn3.ID().Str(), sn2.ID().Str())
|
||||
|
||||
// get archive stats again
|
||||
@@ -246,18 +246,18 @@ func testParallelSaveWithDuplication(t *testing.T, seed int) {
|
||||
}
|
||||
|
||||
for _, errChan := range errChannels {
|
||||
OK(t, <-errChan)
|
||||
rtest.OK(t, <-errChan)
|
||||
}
|
||||
|
||||
OK(t, repo.Flush())
|
||||
OK(t, repo.SaveIndex(context.TODO()))
|
||||
rtest.OK(t, repo.Flush())
|
||||
rtest.OK(t, repo.SaveIndex(context.TODO()))
|
||||
|
||||
chkr := createAndInitChecker(t, repo)
|
||||
assertNoUnreferencedPacks(t, chkr)
|
||||
}
|
||||
|
||||
func getRandomData(seed int, size int) []chunker.Chunk {
|
||||
buf := Random(seed, size)
|
||||
buf := rtest.Random(seed, size)
|
||||
var chunks []chunker.Chunk
|
||||
chunker := chunker.New(bytes.NewReader(buf), testPol)
|
||||
|
||||
@@ -292,7 +292,7 @@ func assertNoUnreferencedPacks(t *testing.T, chkr *checker.Checker) {
|
||||
go chkr.Packs(context.TODO(), errChan)
|
||||
|
||||
for err := range errChan {
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,26 +341,26 @@ func TestArchiveNameCollision(t *testing.T) {
|
||||
repo, cleanup := repository.TestRepository(t)
|
||||
defer cleanup()
|
||||
|
||||
dir, cleanup := TempDir(t)
|
||||
dir, cleanup := rtest.TempDir(t)
|
||||
defer cleanup()
|
||||
|
||||
root := filepath.Join(dir, "root")
|
||||
OK(t, os.MkdirAll(root, 0755))
|
||||
rtest.OK(t, os.MkdirAll(root, 0755))
|
||||
|
||||
OK(t, ioutil.WriteFile(filepath.Join(dir, "testfile"), []byte("testfile1"), 0644))
|
||||
OK(t, ioutil.WriteFile(filepath.Join(dir, "root", "testfile"), []byte("testfile2"), 0644))
|
||||
rtest.OK(t, ioutil.WriteFile(filepath.Join(dir, "testfile"), []byte("testfile1"), 0644))
|
||||
rtest.OK(t, ioutil.WriteFile(filepath.Join(dir, "root", "testfile"), []byte("testfile2"), 0644))
|
||||
|
||||
defer chdir(t, root)()
|
||||
|
||||
arch := archiver.New(repo)
|
||||
|
||||
sn, id, err := arch.Snapshot(context.TODO(), nil, []string{"testfile", filepath.Join("..", "testfile")}, nil, "localhost", nil, time.Now())
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
t.Logf("snapshot archived as %v", id)
|
||||
|
||||
tree, err := repo.LoadTree(context.TODO(), *sn.Tree)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
if len(tree.Nodes) != 2 {
|
||||
t.Fatalf("tree has %d nodes, wanted 2: %v", len(tree.Nodes), tree.Nodes)
|
||||
|
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/restic/restic/internal/backend/test"
|
||||
"github.com/restic/restic/internal/errors"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
. "github.com/restic/restic/internal/test"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
func newAzureTestSuite(t testing.TB) *test.Suite {
|
||||
@@ -81,7 +81,7 @@ func newAzureTestSuite(t testing.TB) *test.Suite {
|
||||
func TestBackendAzure(t *testing.T) {
|
||||
defer func() {
|
||||
if t.Skipped() {
|
||||
SkipDisallowed(t, "restic/backend/azure.TestBackendAzure")
|
||||
rtest.SkipDisallowed(t, "restic/backend/azure.TestBackendAzure")
|
||||
}
|
||||
}()
|
||||
|
||||
|
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/restic/restic/internal/backend/test"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
|
||||
. "github.com/restic/restic/internal/test"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
func newB2TestSuite(t testing.TB) *test.Suite {
|
||||
@@ -83,7 +83,7 @@ func testVars(t testing.TB) {
|
||||
func TestBackendB2(t *testing.T) {
|
||||
defer func() {
|
||||
if t.Skipped() {
|
||||
SkipDisallowed(t, "restic/backend/b2.TestBackendB2")
|
||||
rtest.SkipDisallowed(t, "restic/backend/b2.TestBackendB2")
|
||||
}
|
||||
}()
|
||||
|
||||
|
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/restic/restic/internal/backend/test"
|
||||
"github.com/restic/restic/internal/errors"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
. "github.com/restic/restic/internal/test"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
func newGSTestSuite(t testing.TB) *test.Suite {
|
||||
@@ -81,7 +81,7 @@ func newGSTestSuite(t testing.TB) *test.Suite {
|
||||
func TestBackendGS(t *testing.T) {
|
||||
defer func() {
|
||||
if t.Skipped() {
|
||||
SkipDisallowed(t, "restic/backend/gs.TestBackendGS")
|
||||
rtest.SkipDisallowed(t, "restic/backend/gs.TestBackendGS")
|
||||
}
|
||||
}()
|
||||
|
||||
|
@@ -9,11 +9,11 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/restic/restic/internal/restic"
|
||||
. "github.com/restic/restic/internal/test"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
func TestDefaultLayout(t *testing.T) {
|
||||
tempdir, cleanup := TempDir(t)
|
||||
tempdir, cleanup := rtest.TempDir(t)
|
||||
defer cleanup()
|
||||
|
||||
var tests = []struct {
|
||||
@@ -140,7 +140,7 @@ func TestDefaultLayout(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRESTLayout(t *testing.T) {
|
||||
path, cleanup := TempDir(t)
|
||||
path, cleanup := rtest.TempDir(t)
|
||||
defer cleanup()
|
||||
|
||||
var tests = []struct {
|
||||
@@ -286,7 +286,7 @@ func TestRESTLayoutURLs(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestS3LegacyLayout(t *testing.T) {
|
||||
path, cleanup := TempDir(t)
|
||||
path, cleanup := rtest.TempDir(t)
|
||||
defer cleanup()
|
||||
|
||||
var tests = []struct {
|
||||
@@ -354,7 +354,7 @@ func TestS3LegacyLayout(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDetectLayout(t *testing.T) {
|
||||
path, cleanup := TempDir(t)
|
||||
path, cleanup := rtest.TempDir(t)
|
||||
defer cleanup()
|
||||
|
||||
var tests = []struct {
|
||||
@@ -369,7 +369,7 @@ func TestDetectLayout(t *testing.T) {
|
||||
for _, test := range tests {
|
||||
for _, fs := range []Filesystem{fs, nil} {
|
||||
t.Run(fmt.Sprintf("%v/fs-%T", test.filename, fs), func(t *testing.T) {
|
||||
SetupTarTestFixture(t, path, filepath.Join("testdata", test.filename))
|
||||
rtest.SetupTarTestFixture(t, path, filepath.Join("testdata", test.filename))
|
||||
|
||||
layout, err := DetectLayout(fs, filepath.Join(path, "repo"))
|
||||
if err != nil {
|
||||
@@ -385,14 +385,14 @@ func TestDetectLayout(t *testing.T) {
|
||||
t.Fatalf("want layout %v, got %v", test.want, layoutName)
|
||||
}
|
||||
|
||||
RemoveAll(t, filepath.Join(path, "repo"))
|
||||
rtest.RemoveAll(t, filepath.Join(path, "repo"))
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseLayout(t *testing.T) {
|
||||
path, cleanup := TempDir(t)
|
||||
path, cleanup := rtest.TempDir(t)
|
||||
defer cleanup()
|
||||
|
||||
var tests = []struct {
|
||||
@@ -405,7 +405,7 @@ func TestParseLayout(t *testing.T) {
|
||||
{"", "", "*backend.DefaultLayout"},
|
||||
}
|
||||
|
||||
SetupTarTestFixture(t, path, filepath.Join("testdata", "repo-layout-default.tar.gz"))
|
||||
rtest.SetupTarTestFixture(t, path, filepath.Join("testdata", "repo-layout-default.tar.gz"))
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.layoutName, func(t *testing.T) {
|
||||
@@ -432,7 +432,7 @@ func TestParseLayout(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseLayoutInvalid(t *testing.T) {
|
||||
path, cleanup := TempDir(t)
|
||||
path, cleanup := rtest.TempDir(t)
|
||||
defer cleanup()
|
||||
|
||||
var invalidNames = []string{
|
||||
|
@@ -6,11 +6,11 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/restic/restic/internal/restic"
|
||||
. "github.com/restic/restic/internal/test"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
func TestLayout(t *testing.T) {
|
||||
path, cleanup := TempDir(t)
|
||||
path, cleanup := rtest.TempDir(t)
|
||||
defer cleanup()
|
||||
|
||||
var tests = []struct {
|
||||
@@ -33,7 +33,7 @@ func TestLayout(t *testing.T) {
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.filename, func(t *testing.T) {
|
||||
SetupTarTestFixture(t, path, filepath.Join("..", "testdata", test.filename))
|
||||
rtest.SetupTarTestFixture(t, path, filepath.Join("..", "testdata", test.filename))
|
||||
|
||||
repo := filepath.Join(path, "repo")
|
||||
be, err := Open(Config{
|
||||
@@ -75,7 +75,7 @@ func TestLayout(t *testing.T) {
|
||||
t.Errorf("Close() returned error %v", err)
|
||||
}
|
||||
|
||||
RemoveAll(t, filepath.Join(path, "repo"))
|
||||
rtest.RemoveAll(t, filepath.Join(path, "repo"))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@@ -9,14 +9,14 @@ import (
|
||||
"github.com/restic/restic/internal/backend/local"
|
||||
"github.com/restic/restic/internal/backend/test"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
. "github.com/restic/restic/internal/test"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
func newTestSuite(t testing.TB) *test.Suite {
|
||||
return &test.Suite{
|
||||
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
||||
NewConfig: func() (interface{}, error) {
|
||||
dir, err := ioutil.TempDir(TestTempDir, "restic-test-local-")
|
||||
dir, err := ioutil.TempDir(rtest.TestTempDir, "restic-test-local-")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -44,11 +44,11 @@ func newTestSuite(t testing.TB) *test.Suite {
|
||||
// CleanupFn removes data created during the tests.
|
||||
Cleanup: func(config interface{}) error {
|
||||
cfg := config.(local.Config)
|
||||
if !TestCleanupTempDirs {
|
||||
if !rtest.TestCleanupTempDirs {
|
||||
t.Logf("leaving test backend dir at %v", cfg.Path)
|
||||
}
|
||||
|
||||
RemoveAll(t, cfg.Path)
|
||||
rtest.RemoveAll(t, cfg.Path)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
@@ -119,7 +119,7 @@ func removeAll(t testing.TB, dir string) {
|
||||
}
|
||||
|
||||
func TestOpenNotExistingDirectory(t *testing.T) {
|
||||
dir, cleanup := TempDir(t)
|
||||
dir, cleanup := rtest.TempDir(t)
|
||||
defer cleanup()
|
||||
|
||||
// local.Open must not create any files dirs in the repo
|
||||
|
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/restic/restic/internal/backend/rest"
|
||||
"github.com/restic/restic/internal/backend/test"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
. "github.com/restic/restic/internal/test"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
func runRESTServer(ctx context.Context, t testing.TB, dir string) func() {
|
||||
@@ -64,7 +64,7 @@ func newTestSuite(ctx context.Context, t testing.TB) *test.Suite {
|
||||
return &test.Suite{
|
||||
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
||||
NewConfig: func() (interface{}, error) {
|
||||
dir, err := ioutil.TempDir(TestTempDir, "restic-test-rest-")
|
||||
dir, err := ioutil.TempDir(rtest.TestTempDir, "restic-test-rest-")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -103,14 +103,14 @@ func newTestSuite(ctx context.Context, t testing.TB) *test.Suite {
|
||||
func TestBackendREST(t *testing.T) {
|
||||
defer func() {
|
||||
if t.Skipped() {
|
||||
SkipDisallowed(t, "restic/backend/rest.TestBackendREST")
|
||||
rtest.SkipDisallowed(t, "restic/backend/rest.TestBackendREST")
|
||||
}
|
||||
}()
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
dir, cleanup := TempDir(t)
|
||||
dir, cleanup := rtest.TempDir(t)
|
||||
defer cleanup()
|
||||
|
||||
cleanup = runRESTServer(ctx, t, dir)
|
||||
@@ -123,7 +123,7 @@ func BenchmarkBackendREST(t *testing.B) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
dir, cleanup := TempDir(t)
|
||||
dir, cleanup := rtest.TempDir(t)
|
||||
defer cleanup()
|
||||
|
||||
cleanup = runRESTServer(ctx, t, dir)
|
||||
|
@@ -17,7 +17,7 @@ import (
|
||||
"github.com/restic/restic/internal/backend/s3"
|
||||
"github.com/restic/restic/internal/backend/test"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
. "github.com/restic/restic/internal/test"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
func mkdir(t testing.TB, dir string) {
|
||||
@@ -124,7 +124,7 @@ func newMinioTestSuite(ctx context.Context, t testing.TB) *test.Suite {
|
||||
NewConfig: func() (interface{}, error) {
|
||||
cfg := MinioTestConfig{}
|
||||
|
||||
cfg.tempdir, cfg.removeTempdir = TempDir(t)
|
||||
cfg.tempdir, cfg.removeTempdir = rtest.TempDir(t)
|
||||
key, secret := newRandomCredentials(t)
|
||||
cfg.stopServer = runMinio(ctx, t, cfg.tempdir, key, secret)
|
||||
|
||||
@@ -182,7 +182,7 @@ func newMinioTestSuite(ctx context.Context, t testing.TB) *test.Suite {
|
||||
func TestBackendMinio(t *testing.T) {
|
||||
defer func() {
|
||||
if t.Skipped() {
|
||||
SkipDisallowed(t, "restic/backend/s3.TestBackendMinio")
|
||||
rtest.SkipDisallowed(t, "restic/backend/s3.TestBackendMinio")
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -280,7 +280,7 @@ func newS3TestSuite(t testing.TB) *test.Suite {
|
||||
func TestBackendS3(t *testing.T) {
|
||||
defer func() {
|
||||
if t.Skipped() {
|
||||
SkipDisallowed(t, "restic/backend/s3.TestBackendS3")
|
||||
rtest.SkipDisallowed(t, "restic/backend/s3.TestBackendS3")
|
||||
}
|
||||
}()
|
||||
|
||||
|
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
"github.com/restic/restic/internal/backend/sftp"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
. "github.com/restic/restic/internal/test"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
func TestLayout(t *testing.T) {
|
||||
@@ -16,7 +16,7 @@ func TestLayout(t *testing.T) {
|
||||
t.Skip("sftp server binary not available")
|
||||
}
|
||||
|
||||
path, cleanup := TempDir(t)
|
||||
path, cleanup := rtest.TempDir(t)
|
||||
defer cleanup()
|
||||
|
||||
var tests = []struct {
|
||||
@@ -39,7 +39,7 @@ func TestLayout(t *testing.T) {
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.filename, func(t *testing.T) {
|
||||
SetupTarTestFixture(t, path, filepath.Join("..", "testdata", test.filename))
|
||||
rtest.SetupTarTestFixture(t, path, filepath.Join("..", "testdata", test.filename))
|
||||
|
||||
repo := filepath.Join(path, "repo")
|
||||
be, err := sftp.Open(sftp.Config{
|
||||
@@ -82,7 +82,7 @@ func TestLayout(t *testing.T) {
|
||||
t.Errorf("Close() returned error %v", err)
|
||||
}
|
||||
|
||||
RemoveAll(t, filepath.Join(path, "repo"))
|
||||
rtest.RemoveAll(t, filepath.Join(path, "repo"))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@@ -12,12 +12,11 @@ import (
|
||||
"github.com/restic/restic/internal/backend/test"
|
||||
"github.com/restic/restic/internal/errors"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
|
||||
. "github.com/restic/restic/internal/test"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
func findSFTPServerBinary() string {
|
||||
for _, dir := range strings.Split(TestSFTPPath, ":") {
|
||||
for _, dir := range strings.Split(rtest.TestSFTPPath, ":") {
|
||||
testpath := filepath.Join(dir, "sftp-server")
|
||||
_, err := os.Stat(testpath)
|
||||
if !os.IsNotExist(errors.Cause(err)) {
|
||||
@@ -34,7 +33,7 @@ func newTestSuite(t testing.TB) *test.Suite {
|
||||
return &test.Suite{
|
||||
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
||||
NewConfig: func() (interface{}, error) {
|
||||
dir, err := ioutil.TempDir(TestTempDir, "restic-test-sftp-")
|
||||
dir, err := ioutil.TempDir(rtest.TestTempDir, "restic-test-sftp-")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -63,11 +62,11 @@ func newTestSuite(t testing.TB) *test.Suite {
|
||||
// CleanupFn removes data created during the tests.
|
||||
Cleanup: func(config interface{}) error {
|
||||
cfg := config.(sftp.Config)
|
||||
if !TestCleanupTempDirs {
|
||||
if !rtest.TestCleanupTempDirs {
|
||||
t.Logf("leaving test backend dir at %v", cfg.Path)
|
||||
}
|
||||
|
||||
RemoveAll(t, cfg.Path)
|
||||
rtest.RemoveAll(t, cfg.Path)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
@@ -76,7 +75,7 @@ func newTestSuite(t testing.TB) *test.Suite {
|
||||
func TestBackendSFTP(t *testing.T) {
|
||||
defer func() {
|
||||
if t.Skipped() {
|
||||
SkipDisallowed(t, "restic/backend/sftp.TestBackendSFTP")
|
||||
rtest.SkipDisallowed(t, "restic/backend/sftp.TestBackendSFTP")
|
||||
}
|
||||
}()
|
||||
|
||||
|
@@ -7,12 +7,11 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/restic/restic/internal/errors"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
. "github.com/restic/restic/internal/test"
|
||||
|
||||
"github.com/restic/restic/internal/backend/swift"
|
||||
"github.com/restic/restic/internal/backend/test"
|
||||
"github.com/restic/restic/internal/errors"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
func newSwiftTestSuite(t testing.TB) *test.Suite {
|
||||
@@ -100,7 +99,7 @@ func newSwiftTestSuite(t testing.TB) *test.Suite {
|
||||
func TestBackendSwift(t *testing.T) {
|
||||
defer func() {
|
||||
if t.Skipped() {
|
||||
SkipDisallowed(t, "restic/backend/swift.TestBackendSwift")
|
||||
rtest.SkipDisallowed(t, "restic/backend/swift.TestBackendSwift")
|
||||
}
|
||||
}()
|
||||
|
||||
|
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/restic/restic/internal/backend"
|
||||
"github.com/restic/restic/internal/backend/mem"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
. "github.com/restic/restic/internal/test"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
const KiB = 1 << 10
|
||||
@@ -19,14 +19,14 @@ func TestLoadAll(t *testing.T) {
|
||||
b := mem.New()
|
||||
|
||||
for i := 0; i < 20; i++ {
|
||||
data := Random(23+i, rand.Intn(MiB)+500*KiB)
|
||||
data := rtest.Random(23+i, rand.Intn(MiB)+500*KiB)
|
||||
|
||||
id := restic.Hash(data)
|
||||
err := b.Save(context.TODO(), restic.Handle{Name: id.String(), Type: restic.DataFile}, bytes.NewReader(data))
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
buf, err := backend.LoadAll(context.TODO(), b, restic.Handle{Type: restic.DataFile, Name: id.String()})
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
if len(buf) != len(data) {
|
||||
t.Errorf("length of returned buffer does not match, want %d, got %d", len(data), len(buf))
|
||||
@@ -44,14 +44,14 @@ func TestLoadSmallBuffer(t *testing.T) {
|
||||
b := mem.New()
|
||||
|
||||
for i := 0; i < 20; i++ {
|
||||
data := Random(23+i, rand.Intn(MiB)+500*KiB)
|
||||
data := rtest.Random(23+i, rand.Intn(MiB)+500*KiB)
|
||||
|
||||
id := restic.Hash(data)
|
||||
err := b.Save(context.TODO(), restic.Handle{Name: id.String(), Type: restic.DataFile}, bytes.NewReader(data))
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
buf, err := backend.LoadAll(context.TODO(), b, restic.Handle{Type: restic.DataFile, Name: id.String()})
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
if len(buf) != len(data) {
|
||||
t.Errorf("length of returned buffer does not match, want %d, got %d", len(data), len(buf))
|
||||
@@ -69,14 +69,14 @@ func TestLoadLargeBuffer(t *testing.T) {
|
||||
b := mem.New()
|
||||
|
||||
for i := 0; i < 20; i++ {
|
||||
data := Random(23+i, rand.Intn(MiB)+500*KiB)
|
||||
data := rtest.Random(23+i, rand.Intn(MiB)+500*KiB)
|
||||
|
||||
id := restic.Hash(data)
|
||||
err := b.Save(context.TODO(), restic.Handle{Name: id.String(), Type: restic.DataFile}, bytes.NewReader(data))
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
buf, err := backend.LoadAll(context.TODO(), b, restic.Handle{Type: restic.DataFile, Name: id.String()})
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
if len(buf) != len(data) {
|
||||
t.Errorf("length of returned buffer does not match, want %d, got %d", len(data), len(buf))
|
||||
|
@@ -7,7 +7,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/restic/restic/internal/crypto"
|
||||
. "github.com/restic/restic/internal/test"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
|
||||
"github.com/restic/chunker"
|
||||
)
|
||||
@@ -23,24 +23,24 @@ func TestEncryptDecrypt(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, size := range tests {
|
||||
data := Random(42, size)
|
||||
data := rtest.Random(42, size)
|
||||
buf := make([]byte, size+crypto.Extension)
|
||||
|
||||
ciphertext, err := k.Encrypt(buf, data)
|
||||
OK(t, err)
|
||||
Assert(t, len(ciphertext) == len(data)+crypto.Extension,
|
||||
rtest.OK(t, err)
|
||||
rtest.Assert(t, len(ciphertext) == len(data)+crypto.Extension,
|
||||
"ciphertext length does not match: want %d, got %d",
|
||||
len(data)+crypto.Extension, len(ciphertext))
|
||||
|
||||
plaintext := make([]byte, len(ciphertext))
|
||||
n, err := k.Decrypt(plaintext, ciphertext)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
plaintext = plaintext[:n]
|
||||
Assert(t, len(plaintext) == len(data),
|
||||
rtest.Assert(t, len(plaintext) == len(data),
|
||||
"plaintext length does not match: want %d, got %d",
|
||||
len(data), len(plaintext))
|
||||
|
||||
Equals(t, plaintext, data)
|
||||
rtest.Equals(t, plaintext, data)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,21 +50,21 @@ func TestSmallBuffer(t *testing.T) {
|
||||
size := 600
|
||||
data := make([]byte, size)
|
||||
_, err := io.ReadFull(rand.Reader, data)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
ciphertext := make([]byte, size/2)
|
||||
ciphertext, err = k.Encrypt(ciphertext, data)
|
||||
// this must extend the slice
|
||||
Assert(t, cap(ciphertext) > size/2,
|
||||
rtest.Assert(t, cap(ciphertext) > size/2,
|
||||
"expected extended slice, but capacity is only %d bytes",
|
||||
cap(ciphertext))
|
||||
|
||||
// check for the correct plaintext
|
||||
plaintext := make([]byte, len(ciphertext))
|
||||
n, err := k.Decrypt(plaintext, ciphertext)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
plaintext = plaintext[:n]
|
||||
Assert(t, bytes.Equal(plaintext, data),
|
||||
rtest.Assert(t, bytes.Equal(plaintext, data),
|
||||
"wrong plaintext returned")
|
||||
}
|
||||
|
||||
@@ -74,18 +74,18 @@ func TestSameBuffer(t *testing.T) {
|
||||
size := 600
|
||||
data := make([]byte, size)
|
||||
_, err := io.ReadFull(rand.Reader, data)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
ciphertext := make([]byte, 0, size+crypto.Extension)
|
||||
|
||||
ciphertext, err = k.Encrypt(ciphertext, data)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
// use the same buffer for decryption
|
||||
n, err := k.Decrypt(ciphertext, ciphertext)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
ciphertext = ciphertext[:n]
|
||||
Assert(t, bytes.Equal(ciphertext, data),
|
||||
rtest.Assert(t, bytes.Equal(ciphertext, data),
|
||||
"wrong plaintext returned")
|
||||
}
|
||||
|
||||
@@ -95,20 +95,20 @@ func TestCornerCases(t *testing.T) {
|
||||
// nil plaintext should encrypt to the empty string
|
||||
// nil ciphertext should allocate a new slice for the ciphertext
|
||||
c, err := k.Encrypt(nil, nil)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
Assert(t, len(c) == crypto.Extension,
|
||||
rtest.Assert(t, len(c) == crypto.Extension,
|
||||
"wrong length returned for ciphertext, expected 0, got %d",
|
||||
len(c))
|
||||
|
||||
// this should decrypt to nil
|
||||
n, err := k.Decrypt(nil, c)
|
||||
OK(t, err)
|
||||
Equals(t, 0, n)
|
||||
rtest.OK(t, err)
|
||||
rtest.Equals(t, 0, n)
|
||||
|
||||
// test encryption for same slice, this should return an error
|
||||
_, err = k.Encrypt(c, c)
|
||||
Equals(t, crypto.ErrInvalidCiphertext, err)
|
||||
rtest.Equals(t, crypto.ErrInvalidCiphertext, err)
|
||||
}
|
||||
|
||||
func TestLargeEncrypt(t *testing.T) {
|
||||
@@ -121,15 +121,15 @@ func TestLargeEncrypt(t *testing.T) {
|
||||
for _, size := range []int{chunker.MaxSize, chunker.MaxSize + 1, chunker.MaxSize + 1<<20} {
|
||||
data := make([]byte, size)
|
||||
_, err := io.ReadFull(rand.Reader, data)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
ciphertext, err := k.Encrypt(make([]byte, size+crypto.Extension), data)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
plaintext, err := k.Decrypt([]byte{}, ciphertext)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
Equals(t, plaintext, data)
|
||||
rtest.Equals(t, plaintext, data)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ func BenchmarkEncrypt(b *testing.B) {
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
_, err := k.Encrypt(buf, data)
|
||||
OK(b, err)
|
||||
rtest.OK(b, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,13 +159,13 @@ func BenchmarkDecrypt(b *testing.B) {
|
||||
ciphertext := make([]byte, size+crypto.Extension)
|
||||
|
||||
ciphertext, err := k.Encrypt(ciphertext, data)
|
||||
OK(b, err)
|
||||
rtest.OK(b, err)
|
||||
|
||||
b.ResetTimer()
|
||||
b.SetBytes(int64(size))
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
_, err = k.Decrypt(plaintext, ciphertext)
|
||||
OK(b, err)
|
||||
rtest.OK(b, err)
|
||||
}
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@ import (
|
||||
"bazil.org/fuse"
|
||||
"bazil.org/fuse/fs"
|
||||
|
||||
. "github.com/restic/restic/internal/test"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
func testRead(t testing.TB, f *file, offset, length int, data []byte) {
|
||||
@@ -31,7 +31,7 @@ func testRead(t testing.TB, f *file, offset, length int, data []byte) {
|
||||
resp := &fuse.ReadResponse{
|
||||
Data: data,
|
||||
}
|
||||
OK(t, f.Read(ctx, req, resp))
|
||||
rtest.OK(t, f.Read(ctx, req, resp))
|
||||
}
|
||||
|
||||
func firstSnapshotID(t testing.TB, repo restic.Repository) (first restic.ID) {
|
||||
@@ -46,13 +46,13 @@ func firstSnapshotID(t testing.TB, repo restic.Repository) (first restic.ID) {
|
||||
func loadFirstSnapshot(t testing.TB, repo restic.Repository) *restic.Snapshot {
|
||||
id := firstSnapshotID(t, repo)
|
||||
sn, err := restic.LoadSnapshot(context.TODO(), repo, id)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
return sn
|
||||
}
|
||||
|
||||
func loadTree(t testing.TB, repo restic.Repository, id restic.ID) *restic.Tree {
|
||||
tree, err := repo.LoadTree(context.TODO(), id)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
return tree
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ func TestFuseFile(t *testing.T) {
|
||||
defer cancel()
|
||||
|
||||
timestamp, err := time.Parse(time.RFC3339, "2017-01-24T10:42:56+01:00")
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
restic.TestCreateSnapshot(t, repo, timestamp, 2, 0.1)
|
||||
|
||||
sn := loadFirstSnapshot(t, repo)
|
||||
@@ -82,12 +82,12 @@ func TestFuseFile(t *testing.T) {
|
||||
)
|
||||
for _, id := range content {
|
||||
size, err := repo.LookupBlobSize(id, restic.DataBlob)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
filesize += uint64(size)
|
||||
|
||||
buf := restic.NewBlobBuffer(int(size))
|
||||
n, err := repo.LoadBlob(context.TODO(), restic.DataBlob, id, buf)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
if uint(n) != size {
|
||||
t.Fatalf("not enough bytes read for id %v: want %v, got %v", id.Str(), size, n)
|
||||
@@ -118,15 +118,15 @@ func TestFuseFile(t *testing.T) {
|
||||
|
||||
inode := fs.GenerateDynamicInode(1, "foo")
|
||||
f, err := newFile(context.TODO(), root, inode, node)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
attr := fuse.Attr{}
|
||||
OK(t, f.Attr(ctx, &attr))
|
||||
rtest.OK(t, f.Attr(ctx, &attr))
|
||||
|
||||
Equals(t, inode, attr.Inode)
|
||||
Equals(t, node.Mode, attr.Mode)
|
||||
Equals(t, node.Size, attr.Size)
|
||||
Equals(t, (node.Size/uint64(attr.BlockSize))+1, attr.Blocks)
|
||||
rtest.Equals(t, inode, attr.Inode)
|
||||
rtest.Equals(t, node.Mode, attr.Mode)
|
||||
rtest.Equals(t, node.Size, attr.Size)
|
||||
rtest.Equals(t, (node.Size/uint64(attr.BlockSize))+1, attr.Blocks)
|
||||
|
||||
for i := 0; i < 200; i++ {
|
||||
offset := rand.Intn(int(filesize))
|
||||
@@ -142,5 +142,5 @@ func TestFuseFile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
OK(t, f.Release(ctx, nil))
|
||||
rtest.OK(t, f.Release(ctx, nil))
|
||||
}
|
||||
|
@@ -14,7 +14,7 @@ import (
|
||||
"github.com/restic/restic/internal/crypto"
|
||||
"github.com/restic/restic/internal/pack"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
. "github.com/restic/restic/internal/test"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
var testLens = []int{23, 31650, 25860, 10928, 13769, 19862, 5211, 127, 13690, 30231}
|
||||
@@ -30,7 +30,7 @@ func newPack(t testing.TB, k *crypto.Key, lengths []int) ([]Buf, []byte, uint) {
|
||||
for _, l := range lengths {
|
||||
b := make([]byte, l)
|
||||
_, err := io.ReadFull(rand.Reader, b)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
h := sha256.Sum256(b)
|
||||
bufs = append(bufs, Buf{data: b, id: h})
|
||||
}
|
||||
@@ -42,7 +42,7 @@ func newPack(t testing.TB, k *crypto.Key, lengths []int) ([]Buf, []byte, uint) {
|
||||
}
|
||||
|
||||
_, err := p.Finalize()
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
packData := p.Writer().(*bytes.Buffer).Bytes()
|
||||
return bufs, packData, p.Size()
|
||||
@@ -60,27 +60,27 @@ func verifyBlobs(t testing.TB, bufs []Buf, k *crypto.Key, rd io.ReaderAt, packSi
|
||||
written += restic.CiphertextLength(headerSize)
|
||||
|
||||
// check length
|
||||
Equals(t, uint(written), packSize)
|
||||
rtest.Equals(t, uint(written), packSize)
|
||||
|
||||
// read and parse it again
|
||||
entries, err := pack.List(k, rd, int64(packSize))
|
||||
OK(t, err)
|
||||
Equals(t, len(entries), len(bufs))
|
||||
rtest.OK(t, err)
|
||||
rtest.Equals(t, len(entries), len(bufs))
|
||||
|
||||
var buf []byte
|
||||
for i, b := range bufs {
|
||||
e := entries[i]
|
||||
Equals(t, b.id, e.ID)
|
||||
rtest.Equals(t, b.id, e.ID)
|
||||
|
||||
if len(buf) < int(e.Length) {
|
||||
buf = make([]byte, int(e.Length))
|
||||
}
|
||||
buf = buf[:int(e.Length)]
|
||||
n, err := rd.ReadAt(buf, int64(e.Offset))
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
buf = buf[:n]
|
||||
|
||||
Assert(t, bytes.Equal(b.data, buf),
|
||||
rtest.Assert(t, bytes.Equal(b.data, buf),
|
||||
"data for blob %v doesn't match", i)
|
||||
}
|
||||
}
|
||||
@@ -90,7 +90,7 @@ func TestCreatePack(t *testing.T) {
|
||||
k := crypto.NewRandomKey()
|
||||
|
||||
bufs, packData, packSize := newPack(t, k, testLens)
|
||||
Equals(t, uint(len(packData)), packSize)
|
||||
rtest.Equals(t, uint(len(packData)), packSize)
|
||||
verifyBlobs(t, bufs, k, bytes.NewReader(packData), packSize)
|
||||
}
|
||||
|
||||
@@ -106,14 +106,14 @@ func TestBlobTypeJSON(t *testing.T) {
|
||||
for _, test := range blobTypeJSON {
|
||||
// test serialize
|
||||
buf, err := json.Marshal(test.t)
|
||||
OK(t, err)
|
||||
Equals(t, test.res, string(buf))
|
||||
rtest.OK(t, err)
|
||||
rtest.Equals(t, test.res, string(buf))
|
||||
|
||||
// test unserialize
|
||||
var v restic.BlobType
|
||||
err = json.Unmarshal([]byte(test.res), &v)
|
||||
OK(t, err)
|
||||
Equals(t, test.t, v)
|
||||
rtest.OK(t, err)
|
||||
rtest.Equals(t, test.t, v)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ func TestUnpackReadSeeker(t *testing.T) {
|
||||
id := restic.Hash(packData)
|
||||
|
||||
handle := restic.Handle{Type: restic.DataFile, Name: id.String()}
|
||||
OK(t, b.Save(context.TODO(), handle, bytes.NewReader(packData)))
|
||||
rtest.OK(t, b.Save(context.TODO(), handle, bytes.NewReader(packData)))
|
||||
verifyBlobs(t, bufs, k, restic.ReaderAt(b, handle), packSize)
|
||||
}
|
||||
|
||||
@@ -140,6 +140,6 @@ func TestShortPack(t *testing.T) {
|
||||
id := restic.Hash(packData)
|
||||
|
||||
handle := restic.Handle{Type: restic.DataFile, Name: id.String()}
|
||||
OK(t, b.Save(context.TODO(), handle, bytes.NewReader(packData)))
|
||||
rtest.OK(t, b.Save(context.TODO(), handle, bytes.NewReader(packData)))
|
||||
verifyBlobs(t, bufs, k, restic.ReaderAt(b, handle), packSize)
|
||||
}
|
||||
|
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
"github.com/restic/restic/internal/debug"
|
||||
"github.com/restic/restic/internal/pipe"
|
||||
. "github.com/restic/restic/internal/test"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
type stats struct {
|
||||
@@ -27,7 +27,7 @@ func statPath(path string) (stats, error) {
|
||||
var s stats
|
||||
|
||||
// count files and directories with filepath.Walk()
|
||||
err := filepath.Walk(TestWalkerPath, func(p string, fi os.FileInfo, err error) error {
|
||||
err := filepath.Walk(rtest.TestWalkerPath, func(p string, fi os.FileInfo, err error) error {
|
||||
if fi == nil {
|
||||
return err
|
||||
}
|
||||
@@ -47,20 +47,20 @@ func statPath(path string) (stats, error) {
|
||||
const maxWorkers = 100
|
||||
|
||||
func TestPipelineWalkerWithSplit(t *testing.T) {
|
||||
if TestWalkerPath == "" {
|
||||
if rtest.TestWalkerPath == "" {
|
||||
t.Skipf("walkerpath not set, skipping TestPipelineWalker")
|
||||
}
|
||||
|
||||
var err error
|
||||
if !filepath.IsAbs(TestWalkerPath) {
|
||||
TestWalkerPath, err = filepath.Abs(TestWalkerPath)
|
||||
OK(t, err)
|
||||
if !filepath.IsAbs(rtest.TestWalkerPath) {
|
||||
rtest.TestWalkerPath, err = filepath.Abs(rtest.TestWalkerPath)
|
||||
rtest.OK(t, err)
|
||||
}
|
||||
|
||||
before, err := statPath(TestWalkerPath)
|
||||
OK(t, err)
|
||||
before, err := statPath(rtest.TestWalkerPath)
|
||||
rtest.OK(t, err)
|
||||
|
||||
t.Logf("walking path %s with %d dirs, %d files", TestWalkerPath,
|
||||
t.Logf("walking path %s with %d dirs, %d files", rtest.TestWalkerPath,
|
||||
before.dirs, before.files)
|
||||
|
||||
// account for top level dir
|
||||
@@ -128,7 +128,7 @@ func TestPipelineWalkerWithSplit(t *testing.T) {
|
||||
}()
|
||||
|
||||
resCh := make(chan pipe.Result, 1)
|
||||
pipe.Walk(context.TODO(), []string{TestWalkerPath}, acceptAll, jobs, resCh)
|
||||
pipe.Walk(context.TODO(), []string{rtest.TestWalkerPath}, acceptAll, jobs, resCh)
|
||||
|
||||
// wait for all workers to terminate
|
||||
wg.Wait()
|
||||
@@ -136,14 +136,14 @@ func TestPipelineWalkerWithSplit(t *testing.T) {
|
||||
// wait for top-level blob
|
||||
<-resCh
|
||||
|
||||
t.Logf("walked path %s with %d dirs, %d files", TestWalkerPath,
|
||||
t.Logf("walked path %s with %d dirs, %d files", rtest.TestWalkerPath,
|
||||
after.dirs, after.files)
|
||||
|
||||
Assert(t, before == after, "stats do not match, expected %v, got %v", before, after)
|
||||
rtest.Assert(t, before == after, "stats do not match, expected %v, got %v", before, after)
|
||||
}
|
||||
|
||||
func TestPipelineWalker(t *testing.T) {
|
||||
if TestWalkerPath == "" {
|
||||
if rtest.TestWalkerPath == "" {
|
||||
t.Skipf("walkerpath not set, skipping TestPipelineWalker")
|
||||
}
|
||||
|
||||
@@ -151,15 +151,15 @@ func TestPipelineWalker(t *testing.T) {
|
||||
defer cancel()
|
||||
|
||||
var err error
|
||||
if !filepath.IsAbs(TestWalkerPath) {
|
||||
TestWalkerPath, err = filepath.Abs(TestWalkerPath)
|
||||
OK(t, err)
|
||||
if !filepath.IsAbs(rtest.TestWalkerPath) {
|
||||
rtest.TestWalkerPath, err = filepath.Abs(rtest.TestWalkerPath)
|
||||
rtest.OK(t, err)
|
||||
}
|
||||
|
||||
before, err := statPath(TestWalkerPath)
|
||||
OK(t, err)
|
||||
before, err := statPath(rtest.TestWalkerPath)
|
||||
rtest.OK(t, err)
|
||||
|
||||
t.Logf("walking path %s with %d dirs, %d files", TestWalkerPath,
|
||||
t.Logf("walking path %s with %d dirs, %d files", rtest.TestWalkerPath,
|
||||
before.dirs, before.files)
|
||||
|
||||
// account for top level dir
|
||||
@@ -177,7 +177,7 @@ func TestPipelineWalker(t *testing.T) {
|
||||
// channel is closed
|
||||
return
|
||||
}
|
||||
Assert(t, job != nil, "job is nil")
|
||||
rtest.Assert(t, job != nil, "job is nil")
|
||||
|
||||
switch j := job.(type) {
|
||||
case pipe.Dir:
|
||||
@@ -215,7 +215,7 @@ func TestPipelineWalker(t *testing.T) {
|
||||
}
|
||||
|
||||
resCh := make(chan pipe.Result, 1)
|
||||
pipe.Walk(ctx, []string{TestWalkerPath}, acceptAll, jobs, resCh)
|
||||
pipe.Walk(ctx, []string{rtest.TestWalkerPath}, acceptAll, jobs, resCh)
|
||||
|
||||
// wait for all workers to terminate
|
||||
wg.Wait()
|
||||
@@ -223,10 +223,10 @@ func TestPipelineWalker(t *testing.T) {
|
||||
// wait for top-level blob
|
||||
<-resCh
|
||||
|
||||
t.Logf("walked path %s with %d dirs, %d files", TestWalkerPath,
|
||||
t.Logf("walked path %s with %d dirs, %d files", rtest.TestWalkerPath,
|
||||
after.dirs, after.files)
|
||||
|
||||
Assert(t, before == after, "stats do not match, expected %v, got %v", before, after)
|
||||
rtest.Assert(t, before == after, "stats do not match, expected %v, got %v", before, after)
|
||||
}
|
||||
|
||||
func createFile(filename, data string) error {
|
||||
@@ -247,7 +247,7 @@ func createFile(filename, data string) error {
|
||||
|
||||
func TestPipeWalkerError(t *testing.T) {
|
||||
dir, err := ioutil.TempDir("", "restic-test-")
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
base := filepath.Base(dir)
|
||||
|
||||
@@ -264,13 +264,13 @@ func TestPipeWalkerError(t *testing.T) {
|
||||
{[]string{}, false},
|
||||
}
|
||||
|
||||
OK(t, os.Mkdir(filepath.Join(dir, "a"), 0755))
|
||||
OK(t, os.Mkdir(filepath.Join(dir, "b"), 0755))
|
||||
OK(t, os.Mkdir(filepath.Join(dir, "c"), 0755))
|
||||
rtest.OK(t, os.Mkdir(filepath.Join(dir, "a"), 0755))
|
||||
rtest.OK(t, os.Mkdir(filepath.Join(dir, "b"), 0755))
|
||||
rtest.OK(t, os.Mkdir(filepath.Join(dir, "c"), 0755))
|
||||
|
||||
OK(t, createFile(filepath.Join(dir, "a", "file_a"), "file a"))
|
||||
OK(t, createFile(filepath.Join(dir, "b", "file_b"), "file b"))
|
||||
OK(t, createFile(filepath.Join(dir, "c", "file_c"), "file c"))
|
||||
rtest.OK(t, createFile(filepath.Join(dir, "a", "file_a"), "file a"))
|
||||
rtest.OK(t, createFile(filepath.Join(dir, "b", "file_b"), "file b"))
|
||||
rtest.OK(t, createFile(filepath.Join(dir, "c", "file_c"), "file c"))
|
||||
|
||||
ranHook := false
|
||||
testdir := filepath.Join(dir, "b")
|
||||
@@ -286,7 +286,7 @@ func TestPipeWalkerError(t *testing.T) {
|
||||
t.Logf("in hook, removing test file %v", testdir)
|
||||
ranHook = true
|
||||
|
||||
OK(t, os.RemoveAll(testdir))
|
||||
rtest.OK(t, os.RemoveAll(testdir))
|
||||
})
|
||||
|
||||
ctx, cancel := context.WithCancel(context.TODO())
|
||||
@@ -327,12 +327,12 @@ func TestPipeWalkerError(t *testing.T) {
|
||||
|
||||
cancel()
|
||||
|
||||
Assert(t, ranHook, "hook did not run")
|
||||
OK(t, os.RemoveAll(dir))
|
||||
rtest.Assert(t, ranHook, "hook did not run")
|
||||
rtest.OK(t, os.RemoveAll(dir))
|
||||
}
|
||||
|
||||
func BenchmarkPipelineWalker(b *testing.B) {
|
||||
if TestWalkerPath == "" {
|
||||
if rtest.TestWalkerPath == "" {
|
||||
b.Skipf("walkerpath not set, skipping BenchPipelineWalker")
|
||||
}
|
||||
|
||||
@@ -418,7 +418,7 @@ func BenchmarkPipelineWalker(b *testing.B) {
|
||||
}()
|
||||
|
||||
resCh := make(chan pipe.Result, 1)
|
||||
pipe.Walk(ctx, []string{TestWalkerPath}, acceptAll, jobs, resCh)
|
||||
pipe.Walk(ctx, []string{rtest.TestWalkerPath}, acceptAll, jobs, resCh)
|
||||
|
||||
// wait for all workers to terminate
|
||||
wg.Wait()
|
||||
@@ -431,18 +431,18 @@ func BenchmarkPipelineWalker(b *testing.B) {
|
||||
}
|
||||
|
||||
func TestPipelineWalkerMultiple(t *testing.T) {
|
||||
if TestWalkerPath == "" {
|
||||
if rtest.TestWalkerPath == "" {
|
||||
t.Skipf("walkerpath not set, skipping TestPipelineWalker")
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.TODO())
|
||||
defer cancel()
|
||||
|
||||
paths, err := filepath.Glob(filepath.Join(TestWalkerPath, "*"))
|
||||
OK(t, err)
|
||||
paths, err := filepath.Glob(filepath.Join(rtest.TestWalkerPath, "*"))
|
||||
rtest.OK(t, err)
|
||||
|
||||
before, err := statPath(TestWalkerPath)
|
||||
OK(t, err)
|
||||
before, err := statPath(rtest.TestWalkerPath)
|
||||
rtest.OK(t, err)
|
||||
|
||||
t.Logf("walking paths %v with %d dirs, %d files", paths,
|
||||
before.dirs, before.files)
|
||||
@@ -459,7 +459,7 @@ func TestPipelineWalkerMultiple(t *testing.T) {
|
||||
// channel is closed
|
||||
return
|
||||
}
|
||||
Assert(t, job != nil, "job is nil")
|
||||
rtest.Assert(t, job != nil, "job is nil")
|
||||
|
||||
switch j := job.(type) {
|
||||
case pipe.Dir:
|
||||
@@ -507,7 +507,7 @@ func TestPipelineWalkerMultiple(t *testing.T) {
|
||||
|
||||
t.Logf("walked %d paths with %d dirs, %d files", len(paths), after.dirs, after.files)
|
||||
|
||||
Assert(t, before == after, "stats do not match, expected %v, got %v", before, after)
|
||||
rtest.Assert(t, before == after, "stats do not match, expected %v, got %v", before, after)
|
||||
}
|
||||
|
||||
func dirsInPath(path string) int {
|
||||
@@ -530,7 +530,7 @@ func TestPipeWalkerRoot(t *testing.T) {
|
||||
}
|
||||
|
||||
cwd, err := os.Getwd()
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
testPaths := []string{
|
||||
string(filepath.Separator),
|
||||
@@ -546,11 +546,11 @@ func TestPipeWalkerRoot(t *testing.T) {
|
||||
func testPipeWalkerRootWithPath(path string, t *testing.T) {
|
||||
pattern := filepath.Join(path, "*")
|
||||
rootPaths, err := filepath.Glob(pattern)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
for i, p := range rootPaths {
|
||||
rootPaths[i], err = filepath.Rel(path, p)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
}
|
||||
|
||||
t.Logf("paths in %v (pattern %q) expanded to %v items", path, pattern, len(rootPaths))
|
||||
@@ -571,7 +571,7 @@ func testPipeWalkerRootWithPath(path string, t *testing.T) {
|
||||
|
||||
filter := func(p string, fi os.FileInfo) bool {
|
||||
p, err := filepath.Rel(path, p)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
return dirsInPath(p) <= 1
|
||||
}
|
||||
|
||||
|
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/restic/restic/internal/repository"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
. "github.com/restic/restic/internal/test"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
func TestIndexSerialize(t *testing.T) {
|
||||
@@ -52,43 +52,43 @@ func TestIndexSerialize(t *testing.T) {
|
||||
|
||||
wr := bytes.NewBuffer(nil)
|
||||
err := idx.Encode(wr)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
idx2, err := repository.DecodeIndex(wr.Bytes())
|
||||
OK(t, err)
|
||||
Assert(t, idx2 != nil,
|
||||
rtest.OK(t, err)
|
||||
rtest.Assert(t, idx2 != nil,
|
||||
"nil returned for decoded index")
|
||||
|
||||
wr2 := bytes.NewBuffer(nil)
|
||||
err = idx2.Encode(wr2)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
for _, testBlob := range tests {
|
||||
list, err := idx.Lookup(testBlob.id, testBlob.tpe)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
if len(list) != 1 {
|
||||
t.Errorf("expected one result for blob %v, got %v: %v", testBlob.id.Str(), len(list), list)
|
||||
}
|
||||
result := list[0]
|
||||
|
||||
Equals(t, testBlob.pack, result.PackID)
|
||||
Equals(t, testBlob.tpe, result.Type)
|
||||
Equals(t, testBlob.offset, result.Offset)
|
||||
Equals(t, testBlob.length, result.Length)
|
||||
rtest.Equals(t, testBlob.pack, result.PackID)
|
||||
rtest.Equals(t, testBlob.tpe, result.Type)
|
||||
rtest.Equals(t, testBlob.offset, result.Offset)
|
||||
rtest.Equals(t, testBlob.length, result.Length)
|
||||
|
||||
list2, err := idx2.Lookup(testBlob.id, testBlob.tpe)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
if len(list2) != 1 {
|
||||
t.Errorf("expected one result for blob %v, got %v: %v", testBlob.id.Str(), len(list2), list2)
|
||||
}
|
||||
result2 := list2[0]
|
||||
|
||||
Equals(t, testBlob.pack, result2.PackID)
|
||||
Equals(t, testBlob.tpe, result2.Type)
|
||||
Equals(t, testBlob.offset, result2.Offset)
|
||||
Equals(t, testBlob.length, result2.Length)
|
||||
rtest.Equals(t, testBlob.pack, result2.PackID)
|
||||
rtest.Equals(t, testBlob.tpe, result2.Type)
|
||||
rtest.Equals(t, testBlob.offset, result2.Offset)
|
||||
rtest.Equals(t, testBlob.length, result2.Length)
|
||||
}
|
||||
|
||||
// add more blobs to idx
|
||||
@@ -125,28 +125,28 @@ func TestIndexSerialize(t *testing.T) {
|
||||
// serialize idx, unserialize to idx3
|
||||
wr3 := bytes.NewBuffer(nil)
|
||||
err = idx.Finalize(wr3)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
Assert(t, idx.Final(),
|
||||
rtest.Assert(t, idx.Final(),
|
||||
"index not final after encoding")
|
||||
|
||||
id := restic.NewRandomID()
|
||||
OK(t, idx.SetID(id))
|
||||
rtest.OK(t, idx.SetID(id))
|
||||
id2, err := idx.ID()
|
||||
Assert(t, id2.Equal(id),
|
||||
rtest.Assert(t, id2.Equal(id),
|
||||
"wrong ID returned: want %v, got %v", id, id2)
|
||||
|
||||
idx3, err := repository.DecodeIndex(wr3.Bytes())
|
||||
OK(t, err)
|
||||
Assert(t, idx3 != nil,
|
||||
rtest.OK(t, err)
|
||||
rtest.Assert(t, idx3 != nil,
|
||||
"nil returned for decoded index")
|
||||
Assert(t, idx3.Final(),
|
||||
rtest.Assert(t, idx3.Final(),
|
||||
"decoded index is not final")
|
||||
|
||||
// all new blobs must be in the index
|
||||
for _, testBlob := range newtests {
|
||||
list, err := idx3.Lookup(testBlob.id, testBlob.tpe)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
if len(list) != 1 {
|
||||
t.Errorf("expected one result for blob %v, got %v: %v", testBlob.id.Str(), len(list), list)
|
||||
@@ -154,10 +154,10 @@ func TestIndexSerialize(t *testing.T) {
|
||||
|
||||
blob := list[0]
|
||||
|
||||
Equals(t, testBlob.pack, blob.PackID)
|
||||
Equals(t, testBlob.tpe, blob.Type)
|
||||
Equals(t, testBlob.offset, blob.Offset)
|
||||
Equals(t, testBlob.length, blob.Length)
|
||||
rtest.Equals(t, testBlob.pack, blob.PackID)
|
||||
rtest.Equals(t, testBlob.tpe, blob.Type)
|
||||
rtest.Equals(t, testBlob.offset, blob.Offset)
|
||||
rtest.Equals(t, testBlob.length, blob.Length)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ func TestIndexSize(t *testing.T) {
|
||||
wr := bytes.NewBuffer(nil)
|
||||
|
||||
err := idx.Encode(wr)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
t.Logf("Index file size for %d blobs in %d packs is %d", blobs*packs, packs, wr.Len())
|
||||
}
|
||||
@@ -289,11 +289,11 @@ func TestIndexUnserialize(t *testing.T) {
|
||||
oldIdx := restic.IDs{restic.TestParseID("ed54ae36197f4745ebc4b54d10e0f623eaaaedd03013eb7ae90df881b7781452")}
|
||||
|
||||
idx, err := repository.DecodeIndex(docExample)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
for _, test := range exampleTests {
|
||||
list, err := idx.Lookup(test.id, test.tpe)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
if len(list) != 1 {
|
||||
t.Errorf("expected one result for blob %v, got %v: %v", test.id.Str(), len(list), list)
|
||||
@@ -302,13 +302,13 @@ func TestIndexUnserialize(t *testing.T) {
|
||||
|
||||
t.Logf("looking for blob %v/%v, got %v", test.tpe, test.id.Str(), blob)
|
||||
|
||||
Equals(t, test.packID, blob.PackID)
|
||||
Equals(t, test.tpe, blob.Type)
|
||||
Equals(t, test.offset, blob.Offset)
|
||||
Equals(t, test.length, blob.Length)
|
||||
rtest.Equals(t, test.packID, blob.PackID)
|
||||
rtest.Equals(t, test.tpe, blob.Type)
|
||||
rtest.Equals(t, test.offset, blob.Offset)
|
||||
rtest.Equals(t, test.length, blob.Length)
|
||||
}
|
||||
|
||||
Equals(t, oldIdx, idx.Supersedes())
|
||||
rtest.Equals(t, oldIdx, idx.Supersedes())
|
||||
|
||||
blobs := idx.ListPack(exampleLookupTest.packID)
|
||||
if len(blobs) != len(exampleLookupTest.blobs) {
|
||||
@@ -331,30 +331,30 @@ func BenchmarkDecodeIndex(b *testing.B) {
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
_, err := repository.DecodeIndex(docExample)
|
||||
OK(b, err)
|
||||
rtest.OK(b, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIndexUnserializeOld(t *testing.T) {
|
||||
idx, err := repository.DecodeOldIndex(docOldExample)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
for _, test := range exampleTests {
|
||||
list, err := idx.Lookup(test.id, test.tpe)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
if len(list) != 1 {
|
||||
t.Errorf("expected one result for blob %v, got %v: %v", test.id.Str(), len(list), list)
|
||||
}
|
||||
blob := list[0]
|
||||
|
||||
Equals(t, test.packID, blob.PackID)
|
||||
Equals(t, test.tpe, blob.Type)
|
||||
Equals(t, test.offset, blob.Offset)
|
||||
Equals(t, test.length, blob.Length)
|
||||
rtest.Equals(t, test.packID, blob.PackID)
|
||||
rtest.Equals(t, test.tpe, blob.Type)
|
||||
rtest.Equals(t, test.offset, blob.Offset)
|
||||
rtest.Equals(t, test.length, blob.Length)
|
||||
}
|
||||
|
||||
Equals(t, 0, len(idx.Supersedes()))
|
||||
rtest.Equals(t, 0, len(idx.Supersedes()))
|
||||
}
|
||||
|
||||
func TestIndexPacks(t *testing.T) {
|
||||
@@ -377,5 +377,5 @@ func TestIndexPacks(t *testing.T) {
|
||||
}
|
||||
|
||||
idxPacks := idx.Packs()
|
||||
Assert(t, packs.Equals(idxPacks), "packs in index do not match packs added to index")
|
||||
rtest.Assert(t, packs.Equals(idxPacks), "packs in index do not match packs added to index")
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/restic/restic/internal/restic"
|
||||
|
||||
"github.com/restic/restic/internal/repository"
|
||||
. "github.com/restic/restic/internal/test"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
type testIDs []string
|
||||
@@ -102,7 +102,7 @@ func TestFilesInParallel(t *testing.T) {
|
||||
|
||||
for n := uint(1); n < 5; n++ {
|
||||
err := repository.FilesInParallel(context.TODO(), lister, restic.DataFile, n*100, f)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,6 +122,6 @@ func TestFilesInParallelWithError(t *testing.T) {
|
||||
|
||||
for n := uint(1); n < 5; n++ {
|
||||
err := repository.FilesInParallel(context.TODO(), lister, restic.DataFile, n*100, f)
|
||||
Equals(t, errTest, err)
|
||||
rtest.Equals(t, errTest, err)
|
||||
}
|
||||
}
|
||||
|
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/restic/restic/internal/archiver"
|
||||
"github.com/restic/restic/internal/repository"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
. "github.com/restic/restic/internal/test"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
var testSizes = []int{5, 23, 2<<18 + 23, 1 << 20}
|
||||
@@ -27,30 +27,30 @@ func TestSave(t *testing.T) {
|
||||
for _, size := range testSizes {
|
||||
data := make([]byte, size)
|
||||
_, err := io.ReadFull(rnd, data)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
id := restic.Hash(data)
|
||||
|
||||
// save
|
||||
sid, err := repo.SaveBlob(context.TODO(), restic.DataBlob, data, restic.ID{})
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
Equals(t, id, sid)
|
||||
rtest.Equals(t, id, sid)
|
||||
|
||||
OK(t, repo.Flush())
|
||||
// OK(t, repo.SaveIndex())
|
||||
rtest.OK(t, repo.Flush())
|
||||
// rtest.OK(t, repo.SaveIndex())
|
||||
|
||||
// read back
|
||||
buf := restic.NewBlobBuffer(size)
|
||||
n, err := repo.LoadBlob(context.TODO(), restic.DataBlob, id, buf)
|
||||
OK(t, err)
|
||||
Equals(t, len(buf), n)
|
||||
rtest.OK(t, err)
|
||||
rtest.Equals(t, len(buf), n)
|
||||
|
||||
Assert(t, len(buf) == len(data),
|
||||
rtest.Assert(t, len(buf) == len(data),
|
||||
"number of bytes read back does not match: expected %d, got %d",
|
||||
len(data), len(buf))
|
||||
|
||||
Assert(t, bytes.Equal(buf, data),
|
||||
rtest.Assert(t, bytes.Equal(buf, data),
|
||||
"data does not match: expected %02x, got %02x",
|
||||
data, buf)
|
||||
}
|
||||
@@ -63,28 +63,28 @@ func TestSaveFrom(t *testing.T) {
|
||||
for _, size := range testSizes {
|
||||
data := make([]byte, size)
|
||||
_, err := io.ReadFull(rnd, data)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
id := restic.Hash(data)
|
||||
|
||||
// save
|
||||
id2, err := repo.SaveBlob(context.TODO(), restic.DataBlob, data, id)
|
||||
OK(t, err)
|
||||
Equals(t, id, id2)
|
||||
rtest.OK(t, err)
|
||||
rtest.Equals(t, id, id2)
|
||||
|
||||
OK(t, repo.Flush())
|
||||
rtest.OK(t, repo.Flush())
|
||||
|
||||
// read back
|
||||
buf := restic.NewBlobBuffer(size)
|
||||
n, err := repo.LoadBlob(context.TODO(), restic.DataBlob, id, buf)
|
||||
OK(t, err)
|
||||
Equals(t, len(buf), n)
|
||||
rtest.OK(t, err)
|
||||
rtest.Equals(t, len(buf), n)
|
||||
|
||||
Assert(t, len(buf) == len(data),
|
||||
rtest.Assert(t, len(buf) == len(data),
|
||||
"number of bytes read back does not match: expected %d, got %d",
|
||||
len(data), len(buf))
|
||||
|
||||
Assert(t, bytes.Equal(buf, data),
|
||||
rtest.Assert(t, bytes.Equal(buf, data),
|
||||
"data does not match: expected %02x, got %02x",
|
||||
data, buf)
|
||||
}
|
||||
@@ -98,7 +98,7 @@ func BenchmarkSaveAndEncrypt(t *testing.B) {
|
||||
|
||||
data := make([]byte, size)
|
||||
_, err := io.ReadFull(rnd, data)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
id := restic.ID(sha256.Sum256(data))
|
||||
|
||||
@@ -108,7 +108,7 @@ func BenchmarkSaveAndEncrypt(t *testing.B) {
|
||||
for i := 0; i < t.N; i++ {
|
||||
// save
|
||||
_, err = repo.SaveBlob(context.TODO(), restic.DataBlob, data, id)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,35 +116,35 @@ func TestLoadTree(t *testing.T) {
|
||||
repo, cleanup := repository.TestRepository(t)
|
||||
defer cleanup()
|
||||
|
||||
if BenchArchiveDirectory == "" {
|
||||
if rtest.BenchArchiveDirectory == "" {
|
||||
t.Skip("benchdir not set, skipping")
|
||||
}
|
||||
|
||||
// archive a few files
|
||||
sn := archiver.TestSnapshot(t, repo, BenchArchiveDirectory, nil)
|
||||
OK(t, repo.Flush())
|
||||
sn := archiver.TestSnapshot(t, repo, rtest.BenchArchiveDirectory, nil)
|
||||
rtest.OK(t, repo.Flush())
|
||||
|
||||
_, err := repo.LoadTree(context.TODO(), *sn.Tree)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
}
|
||||
|
||||
func BenchmarkLoadTree(t *testing.B) {
|
||||
repo, cleanup := repository.TestRepository(t)
|
||||
defer cleanup()
|
||||
|
||||
if BenchArchiveDirectory == "" {
|
||||
if rtest.BenchArchiveDirectory == "" {
|
||||
t.Skip("benchdir not set, skipping")
|
||||
}
|
||||
|
||||
// archive a few files
|
||||
sn := archiver.TestSnapshot(t, repo, BenchArchiveDirectory, nil)
|
||||
OK(t, repo.Flush())
|
||||
sn := archiver.TestSnapshot(t, repo, rtest.BenchArchiveDirectory, nil)
|
||||
rtest.OK(t, repo.Flush())
|
||||
|
||||
t.ResetTimer()
|
||||
|
||||
for i := 0; i < t.N; i++ {
|
||||
_, err := repo.LoadTree(context.TODO(), *sn.Tree)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,11 +155,11 @@ func TestLoadBlob(t *testing.T) {
|
||||
length := 1000000
|
||||
buf := restic.NewBlobBuffer(length)
|
||||
_, err := io.ReadFull(rnd, buf)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
id, err := repo.SaveBlob(context.TODO(), restic.DataBlob, buf, restic.ID{})
|
||||
OK(t, err)
|
||||
OK(t, repo.Flush())
|
||||
rtest.OK(t, err)
|
||||
rtest.OK(t, repo.Flush())
|
||||
|
||||
// first, test with buffers that are too small
|
||||
for _, testlength := range []int{length - 20, length, restic.CiphertextLength(length) - 1} {
|
||||
@@ -200,18 +200,18 @@ func BenchmarkLoadBlob(b *testing.B) {
|
||||
length := 1000000
|
||||
buf := restic.NewBlobBuffer(length)
|
||||
_, err := io.ReadFull(rnd, buf)
|
||||
OK(b, err)
|
||||
rtest.OK(b, err)
|
||||
|
||||
id, err := repo.SaveBlob(context.TODO(), restic.DataBlob, buf, restic.ID{})
|
||||
OK(b, err)
|
||||
OK(b, repo.Flush())
|
||||
rtest.OK(b, err)
|
||||
rtest.OK(b, repo.Flush())
|
||||
|
||||
b.ResetTimer()
|
||||
b.SetBytes(int64(length))
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
n, err := repo.LoadBlob(context.TODO(), restic.DataBlob, id, buf)
|
||||
OK(b, err)
|
||||
rtest.OK(b, err)
|
||||
if n != length {
|
||||
b.Errorf("wanted %d bytes, got %d", length, n)
|
||||
}
|
||||
@@ -230,20 +230,20 @@ func BenchmarkLoadAndDecrypt(b *testing.B) {
|
||||
length := 1000000
|
||||
buf := restic.NewBlobBuffer(length)
|
||||
_, err := io.ReadFull(rnd, buf)
|
||||
OK(b, err)
|
||||
rtest.OK(b, err)
|
||||
|
||||
dataID := restic.Hash(buf)
|
||||
|
||||
storageID, err := repo.SaveUnpacked(context.TODO(), restic.DataFile, buf)
|
||||
OK(b, err)
|
||||
// OK(b, repo.Flush())
|
||||
rtest.OK(b, err)
|
||||
// rtest.OK(b, repo.Flush())
|
||||
|
||||
b.ResetTimer()
|
||||
b.SetBytes(int64(length))
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
data, err := repo.LoadAndDecrypt(context.TODO(), restic.DataFile, storageID)
|
||||
OK(b, err)
|
||||
rtest.OK(b, err)
|
||||
if len(data) != length {
|
||||
b.Errorf("wanted %d bytes, got %d", length, len(data))
|
||||
}
|
||||
@@ -259,7 +259,7 @@ func TestLoadJSONUnpacked(t *testing.T) {
|
||||
repo, cleanup := repository.TestRepository(t)
|
||||
defer cleanup()
|
||||
|
||||
if BenchArchiveDirectory == "" {
|
||||
if rtest.BenchArchiveDirectory == "" {
|
||||
t.Skip("benchdir not set, skipping")
|
||||
}
|
||||
|
||||
@@ -269,26 +269,26 @@ func TestLoadJSONUnpacked(t *testing.T) {
|
||||
sn.Username = "test!"
|
||||
|
||||
id, err := repo.SaveJSONUnpacked(context.TODO(), restic.SnapshotFile, &sn)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
var sn2 restic.Snapshot
|
||||
|
||||
// restore
|
||||
err = repo.LoadJSONUnpacked(context.TODO(), restic.SnapshotFile, id, &sn2)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
Equals(t, sn.Hostname, sn2.Hostname)
|
||||
Equals(t, sn.Username, sn2.Username)
|
||||
rtest.Equals(t, sn.Hostname, sn2.Hostname)
|
||||
rtest.Equals(t, sn.Username, sn2.Username)
|
||||
}
|
||||
|
||||
var repoFixture = filepath.Join("testdata", "test-repo.tar.gz")
|
||||
|
||||
func TestRepositoryLoadIndex(t *testing.T) {
|
||||
repodir, cleanup := Env(t, repoFixture)
|
||||
repodir, cleanup := rtest.Env(t, repoFixture)
|
||||
defer cleanup()
|
||||
|
||||
repo := repository.TestOpenLocal(t, repodir)
|
||||
OK(t, repo.LoadIndex(context.TODO()))
|
||||
rtest.OK(t, repo.LoadIndex(context.TODO()))
|
||||
}
|
||||
|
||||
func BenchmarkLoadIndex(b *testing.B) {
|
||||
@@ -312,18 +312,18 @@ func BenchmarkLoadIndex(b *testing.B) {
|
||||
}
|
||||
|
||||
id, err := repository.SaveIndex(context.TODO(), repo, idx)
|
||||
OK(b, err)
|
||||
rtest.OK(b, err)
|
||||
|
||||
b.Logf("index saved as %v (%v entries)", id.Str(), idx.Count(restic.DataBlob))
|
||||
fi, err := repo.Backend().Stat(context.TODO(), restic.Handle{Type: restic.IndexFile, Name: id.String()})
|
||||
OK(b, err)
|
||||
rtest.OK(b, err)
|
||||
b.Logf("filesize is %v", fi.Size)
|
||||
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
_, err := repository.LoadIndex(context.TODO(), repo, id)
|
||||
OK(b, err)
|
||||
rtest.OK(b, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,10 +334,10 @@ func saveRandomDataBlobs(t testing.TB, repo restic.Repository, num int, sizeMax
|
||||
|
||||
buf := make([]byte, size)
|
||||
_, err := io.ReadFull(rnd, buf)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
_, err = repo.SaveBlob(context.TODO(), restic.DataBlob, buf, restic.ID{})
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -352,26 +352,26 @@ func TestRepositoryIncrementalIndex(t *testing.T) {
|
||||
// add 3 packs, write intermediate index
|
||||
for i := 0; i < 3; i++ {
|
||||
saveRandomDataBlobs(t, repo, 5, 1<<15)
|
||||
OK(t, repo.Flush())
|
||||
rtest.OK(t, repo.Flush())
|
||||
}
|
||||
|
||||
OK(t, repo.SaveFullIndex(context.TODO()))
|
||||
rtest.OK(t, repo.SaveFullIndex(context.TODO()))
|
||||
}
|
||||
|
||||
// add another 5 packs
|
||||
for i := 0; i < 5; i++ {
|
||||
saveRandomDataBlobs(t, repo, 5, 1<<15)
|
||||
OK(t, repo.Flush())
|
||||
rtest.OK(t, repo.Flush())
|
||||
}
|
||||
|
||||
// save final index
|
||||
OK(t, repo.SaveIndex(context.TODO()))
|
||||
rtest.OK(t, repo.SaveIndex(context.TODO()))
|
||||
|
||||
packEntries := make(map[restic.ID]map[restic.ID]struct{})
|
||||
|
||||
for id := range repo.List(context.TODO(), restic.IndexFile) {
|
||||
idx, err := repository.LoadIndex(context.TODO(), repo, id)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
for pb := range idx.Each(context.TODO()) {
|
||||
if _, ok := packEntries[pb.PackID]; !ok {
|
||||
|
@@ -5,7 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/restic/restic/internal/restic"
|
||||
. "github.com/restic/restic/internal/test"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
type saver func(restic.FileType, interface{}) (restic.ID, error)
|
||||
@@ -23,7 +23,7 @@ func (l loader) LoadJSONUnpacked(ctx context.Context, t restic.FileType, id rest
|
||||
func TestConfig(t *testing.T) {
|
||||
resultConfig := restic.Config{}
|
||||
save := func(tpe restic.FileType, arg interface{}) (restic.ID, error) {
|
||||
Assert(t, tpe == restic.ConfigFile,
|
||||
rtest.Assert(t, tpe == restic.ConfigFile,
|
||||
"wrong backend type: got %v, wanted %v",
|
||||
tpe, restic.ConfigFile)
|
||||
|
||||
@@ -33,12 +33,12 @@ func TestConfig(t *testing.T) {
|
||||
}
|
||||
|
||||
cfg1, err := restic.CreateConfig()
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
_, err = saver(save).SaveJSONUnpacked(restic.ConfigFile, cfg1)
|
||||
|
||||
load := func(ctx context.Context, tpe restic.FileType, id restic.ID, arg interface{}) error {
|
||||
Assert(t, tpe == restic.ConfigFile,
|
||||
rtest.Assert(t, tpe == restic.ConfigFile,
|
||||
"wrong backend type: got %v, wanted %v",
|
||||
tpe, restic.ConfigFile)
|
||||
|
||||
@@ -48,8 +48,8 @@ func TestConfig(t *testing.T) {
|
||||
}
|
||||
|
||||
cfg2, err := restic.LoadConfig(context.TODO(), loader(load))
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
Assert(t, cfg1 == cfg2,
|
||||
rtest.Assert(t, cfg1 == cfg2,
|
||||
"configs aren't equal: %v != %v", cfg1, cfg2)
|
||||
}
|
||||
|
@@ -4,7 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/restic/restic/internal/restic"
|
||||
. "github.com/restic/restic/internal/test"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
// TestHardLinks contains various tests for HardlinkIndex.
|
||||
@@ -17,19 +17,19 @@ func TestHardLinks(t *testing.T) {
|
||||
|
||||
var sresult string
|
||||
sresult = idx.GetFilename(1, 2)
|
||||
Equals(t, sresult, "inode1-file1-on-device2")
|
||||
rtest.Equals(t, sresult, "inode1-file1-on-device2")
|
||||
|
||||
sresult = idx.GetFilename(2, 3)
|
||||
Equals(t, sresult, "inode2-file2-on-device3")
|
||||
rtest.Equals(t, sresult, "inode2-file2-on-device3")
|
||||
|
||||
var bresult bool
|
||||
bresult = idx.Has(1, 2)
|
||||
Equals(t, bresult, true)
|
||||
rtest.Equals(t, bresult, true)
|
||||
|
||||
bresult = idx.Has(1, 3)
|
||||
Equals(t, bresult, false)
|
||||
rtest.Equals(t, bresult, false)
|
||||
|
||||
idx.Remove(1, 2)
|
||||
bresult = idx.Has(1, 2)
|
||||
Equals(t, bresult, false)
|
||||
rtest.Equals(t, bresult, false)
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
"github.com/restic/restic/internal/repository"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
. "github.com/restic/restic/internal/test"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
func TestLock(t *testing.T) {
|
||||
@@ -16,9 +16,9 @@ func TestLock(t *testing.T) {
|
||||
defer cleanup()
|
||||
|
||||
lock, err := restic.NewLock(context.TODO(), repo)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
OK(t, lock.Unlock())
|
||||
rtest.OK(t, lock.Unlock())
|
||||
}
|
||||
|
||||
func TestDoubleUnlock(t *testing.T) {
|
||||
@@ -26,12 +26,12 @@ func TestDoubleUnlock(t *testing.T) {
|
||||
defer cleanup()
|
||||
|
||||
lock, err := restic.NewLock(context.TODO(), repo)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
OK(t, lock.Unlock())
|
||||
rtest.OK(t, lock.Unlock())
|
||||
|
||||
err = lock.Unlock()
|
||||
Assert(t, err != nil,
|
||||
rtest.Assert(t, err != nil,
|
||||
"double unlock didn't return an error, got %v", err)
|
||||
}
|
||||
|
||||
@@ -40,13 +40,13 @@ func TestMultipleLock(t *testing.T) {
|
||||
defer cleanup()
|
||||
|
||||
lock1, err := restic.NewLock(context.TODO(), repo)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
lock2, err := restic.NewLock(context.TODO(), repo)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
OK(t, lock1.Unlock())
|
||||
OK(t, lock2.Unlock())
|
||||
rtest.OK(t, lock1.Unlock())
|
||||
rtest.OK(t, lock2.Unlock())
|
||||
}
|
||||
|
||||
func TestLockExclusive(t *testing.T) {
|
||||
@@ -54,8 +54,8 @@ func TestLockExclusive(t *testing.T) {
|
||||
defer cleanup()
|
||||
|
||||
elock, err := restic.NewExclusiveLock(context.TODO(), repo)
|
||||
OK(t, err)
|
||||
OK(t, elock.Unlock())
|
||||
rtest.OK(t, err)
|
||||
rtest.OK(t, elock.Unlock())
|
||||
}
|
||||
|
||||
func TestLockOnExclusiveLockedRepo(t *testing.T) {
|
||||
@@ -63,16 +63,16 @@ func TestLockOnExclusiveLockedRepo(t *testing.T) {
|
||||
defer cleanup()
|
||||
|
||||
elock, err := restic.NewExclusiveLock(context.TODO(), repo)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
lock, err := restic.NewLock(context.TODO(), repo)
|
||||
Assert(t, err != nil,
|
||||
rtest.Assert(t, err != nil,
|
||||
"create normal lock with exclusively locked repo didn't return an error")
|
||||
Assert(t, restic.IsAlreadyLocked(err),
|
||||
rtest.Assert(t, restic.IsAlreadyLocked(err),
|
||||
"create normal lock with exclusively locked repo didn't return the correct error")
|
||||
|
||||
OK(t, lock.Unlock())
|
||||
OK(t, elock.Unlock())
|
||||
rtest.OK(t, lock.Unlock())
|
||||
rtest.OK(t, elock.Unlock())
|
||||
}
|
||||
|
||||
func TestExclusiveLockOnLockedRepo(t *testing.T) {
|
||||
@@ -80,16 +80,16 @@ func TestExclusiveLockOnLockedRepo(t *testing.T) {
|
||||
defer cleanup()
|
||||
|
||||
elock, err := restic.NewLock(context.TODO(), repo)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
lock, err := restic.NewExclusiveLock(context.TODO(), repo)
|
||||
Assert(t, err != nil,
|
||||
rtest.Assert(t, err != nil,
|
||||
"create normal lock with exclusively locked repo didn't return an error")
|
||||
Assert(t, restic.IsAlreadyLocked(err),
|
||||
rtest.Assert(t, restic.IsAlreadyLocked(err),
|
||||
"create normal lock with exclusively locked repo didn't return the correct error")
|
||||
|
||||
OK(t, lock.Unlock())
|
||||
OK(t, elock.Unlock())
|
||||
rtest.OK(t, lock.Unlock())
|
||||
rtest.OK(t, elock.Unlock())
|
||||
}
|
||||
|
||||
func createFakeLock(repo restic.Repository, t time.Time, pid int) (restic.ID, error) {
|
||||
@@ -141,7 +141,7 @@ var staleLockTests = []struct {
|
||||
|
||||
func TestLockStale(t *testing.T) {
|
||||
hostname, err := os.Hostname()
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
otherHostname := "other-" + hostname
|
||||
|
||||
@@ -152,12 +152,12 @@ func TestLockStale(t *testing.T) {
|
||||
Hostname: hostname,
|
||||
}
|
||||
|
||||
Assert(t, lock.Stale() == test.stale,
|
||||
rtest.Assert(t, lock.Stale() == test.stale,
|
||||
"TestStaleLock: test %d failed: expected stale: %v, got %v",
|
||||
i, test.stale, !test.stale)
|
||||
|
||||
lock.Hostname = otherHostname
|
||||
Assert(t, lock.Stale() == test.staleOnOtherHost,
|
||||
rtest.Assert(t, lock.Stale() == test.staleOnOtherHost,
|
||||
"TestStaleLock: test %d failed: expected staleOnOtherHost: %v, got %v",
|
||||
i, test.staleOnOtherHost, !test.staleOnOtherHost)
|
||||
}
|
||||
@@ -166,7 +166,7 @@ func TestLockStale(t *testing.T) {
|
||||
func lockExists(repo restic.Repository, t testing.TB, id restic.ID) bool {
|
||||
h := restic.Handle{Type: restic.LockFile, Name: id.String()}
|
||||
exists, err := repo.Backend().Test(context.TODO(), h)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
return exists
|
||||
}
|
||||
@@ -176,24 +176,24 @@ func TestLockWithStaleLock(t *testing.T) {
|
||||
defer cleanup()
|
||||
|
||||
id1, err := createFakeLock(repo, time.Now().Add(-time.Hour), os.Getpid())
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
id2, err := createFakeLock(repo, time.Now().Add(-time.Minute), os.Getpid())
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
id3, err := createFakeLock(repo, time.Now().Add(-time.Minute), os.Getpid()+500000)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
OK(t, restic.RemoveStaleLocks(context.TODO(), repo))
|
||||
rtest.OK(t, restic.RemoveStaleLocks(context.TODO(), repo))
|
||||
|
||||
Assert(t, lockExists(repo, t, id1) == false,
|
||||
rtest.Assert(t, lockExists(repo, t, id1) == false,
|
||||
"stale lock still exists after RemoveStaleLocks was called")
|
||||
Assert(t, lockExists(repo, t, id2) == true,
|
||||
rtest.Assert(t, lockExists(repo, t, id2) == true,
|
||||
"non-stale lock was removed by RemoveStaleLocks")
|
||||
Assert(t, lockExists(repo, t, id3) == false,
|
||||
rtest.Assert(t, lockExists(repo, t, id3) == false,
|
||||
"stale lock still exists after RemoveStaleLocks was called")
|
||||
|
||||
OK(t, removeLock(repo, id2))
|
||||
rtest.OK(t, removeLock(repo, id2))
|
||||
}
|
||||
|
||||
func TestRemoveAllLocks(t *testing.T) {
|
||||
@@ -201,21 +201,21 @@ func TestRemoveAllLocks(t *testing.T) {
|
||||
defer cleanup()
|
||||
|
||||
id1, err := createFakeLock(repo, time.Now().Add(-time.Hour), os.Getpid())
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
id2, err := createFakeLock(repo, time.Now().Add(-time.Minute), os.Getpid())
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
id3, err := createFakeLock(repo, time.Now().Add(-time.Minute), os.Getpid()+500000)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
OK(t, restic.RemoveAllLocks(context.TODO(), repo))
|
||||
rtest.OK(t, restic.RemoveAllLocks(context.TODO(), repo))
|
||||
|
||||
Assert(t, lockExists(repo, t, id1) == false,
|
||||
rtest.Assert(t, lockExists(repo, t, id1) == false,
|
||||
"lock still exists after RemoveAllLocks was called")
|
||||
Assert(t, lockExists(repo, t, id2) == false,
|
||||
rtest.Assert(t, lockExists(repo, t, id2) == false,
|
||||
"lock still exists after RemoveAllLocks was called")
|
||||
Assert(t, lockExists(repo, t, id3) == false,
|
||||
rtest.Assert(t, lockExists(repo, t, id3) == false,
|
||||
"lock still exists after RemoveAllLocks was called")
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@ func TestLockRefresh(t *testing.T) {
|
||||
defer cleanup()
|
||||
|
||||
lock, err := restic.NewLock(context.TODO(), repo)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
var lockID *restic.ID
|
||||
for id := range repo.List(context.TODO(), restic.LockFile) {
|
||||
@@ -234,7 +234,7 @@ func TestLockRefresh(t *testing.T) {
|
||||
lockID = &id
|
||||
}
|
||||
|
||||
OK(t, lock.Refresh(context.TODO()))
|
||||
rtest.OK(t, lock.Refresh(context.TODO()))
|
||||
|
||||
var lockID2 *restic.ID
|
||||
for id := range repo.List(context.TODO(), restic.LockFile) {
|
||||
@@ -244,7 +244,7 @@ func TestLockRefresh(t *testing.T) {
|
||||
lockID2 = &id
|
||||
}
|
||||
|
||||
Assert(t, !lockID.Equal(*lockID2),
|
||||
rtest.Assert(t, !lockID.Equal(*lockID2),
|
||||
"expected a new ID after lock refresh, got the same")
|
||||
OK(t, lock.Unlock())
|
||||
rtest.OK(t, lock.Unlock())
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/restic/restic/internal/restic"
|
||||
. "github.com/restic/restic/internal/test"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
func BenchmarkNodeFillUser(t *testing.B) {
|
||||
@@ -32,8 +32,8 @@ func BenchmarkNodeFillUser(t *testing.B) {
|
||||
restic.NodeFromFileInfo(path, fi)
|
||||
}
|
||||
|
||||
OK(t, tempfile.Close())
|
||||
RemoveAll(t, tempfile.Name())
|
||||
rtest.OK(t, tempfile.Close())
|
||||
rtest.RemoveAll(t, tempfile.Name())
|
||||
}
|
||||
|
||||
func BenchmarkNodeFromFileInfo(t *testing.B) {
|
||||
@@ -58,8 +58,8 @@ func BenchmarkNodeFromFileInfo(t *testing.B) {
|
||||
}
|
||||
}
|
||||
|
||||
OK(t, tempfile.Close())
|
||||
RemoveAll(t, tempfile.Name())
|
||||
rtest.OK(t, tempfile.Close())
|
||||
rtest.RemoveAll(t, tempfile.Name())
|
||||
}
|
||||
|
||||
func parseTime(s string) time.Time {
|
||||
@@ -166,12 +166,12 @@ var nodeTests = []restic.Node{
|
||||
}
|
||||
|
||||
func TestNodeRestoreAt(t *testing.T) {
|
||||
tempdir, err := ioutil.TempDir(TestTempDir, "restic-test-")
|
||||
OK(t, err)
|
||||
tempdir, err := ioutil.TempDir(rtest.TestTempDir, "restic-test-")
|
||||
rtest.OK(t, err)
|
||||
|
||||
defer func() {
|
||||
if TestCleanupTempDirs {
|
||||
RemoveAll(t, tempdir)
|
||||
if rtest.TestCleanupTempDirs {
|
||||
rtest.RemoveAll(t, tempdir)
|
||||
} else {
|
||||
t.Logf("leaving tempdir at %v", tempdir)
|
||||
}
|
||||
@@ -181,35 +181,35 @@ func TestNodeRestoreAt(t *testing.T) {
|
||||
|
||||
for _, test := range nodeTests {
|
||||
nodePath := filepath.Join(tempdir, test.Name)
|
||||
OK(t, test.CreateAt(context.TODO(), nodePath, nil, idx))
|
||||
rtest.OK(t, test.CreateAt(context.TODO(), nodePath, nil, idx))
|
||||
|
||||
if test.Type == "symlink" && runtime.GOOS == "windows" {
|
||||
continue
|
||||
}
|
||||
if test.Type == "dir" {
|
||||
OK(t, test.RestoreTimestamps(nodePath))
|
||||
rtest.OK(t, test.RestoreTimestamps(nodePath))
|
||||
}
|
||||
|
||||
fi, err := os.Lstat(nodePath)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
n2, err := restic.NodeFromFileInfo(nodePath, fi)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
Assert(t, test.Name == n2.Name,
|
||||
rtest.Assert(t, test.Name == n2.Name,
|
||||
"%v: name doesn't match (%v != %v)", test.Type, test.Name, n2.Name)
|
||||
Assert(t, test.Type == n2.Type,
|
||||
rtest.Assert(t, test.Type == n2.Type,
|
||||
"%v: type doesn't match (%v != %v)", test.Type, test.Type, n2.Type)
|
||||
Assert(t, test.Size == n2.Size,
|
||||
rtest.Assert(t, test.Size == n2.Size,
|
||||
"%v: size doesn't match (%v != %v)", test.Size, test.Size, n2.Size)
|
||||
|
||||
if runtime.GOOS != "windows" {
|
||||
Assert(t, test.UID == n2.UID,
|
||||
rtest.Assert(t, test.UID == n2.UID,
|
||||
"%v: UID doesn't match (%v != %v)", test.Type, test.UID, n2.UID)
|
||||
Assert(t, test.GID == n2.GID,
|
||||
rtest.Assert(t, test.GID == n2.GID,
|
||||
"%v: GID doesn't match (%v != %v)", test.Type, test.GID, n2.GID)
|
||||
if test.Type != "symlink" {
|
||||
Assert(t, test.Mode == n2.Mode,
|
||||
rtest.Assert(t, test.Mode == n2.Mode,
|
||||
"%v: mode doesn't match (0%o != 0%o)", test.Type, test.Mode, n2.Mode)
|
||||
}
|
||||
}
|
||||
@@ -240,5 +240,5 @@ func AssertFsTimeEqual(t *testing.T, label string, nodeType string, t1 time.Time
|
||||
equal = t1.Equal(t2)
|
||||
}
|
||||
|
||||
Assert(t, equal, "%s: %s doesn't match (%v != %v)", label, nodeType, t1, t2)
|
||||
rtest.Assert(t, equal, "%s: %s doesn't match (%v != %v)", label, nodeType, t1, t2)
|
||||
}
|
||||
|
@@ -5,12 +5,12 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/restic/restic/internal/restic"
|
||||
. "github.com/restic/restic/internal/test"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
func TestNewSnapshot(t *testing.T) {
|
||||
paths := []string{"/home/foobar"}
|
||||
|
||||
_, err := restic.NewSnapshot(paths, nil, "foo", time.Now())
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
"github.com/restic/restic/internal/repository"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
. "github.com/restic/restic/internal/test"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
var testFiles = []struct {
|
||||
@@ -23,25 +23,25 @@ var testFiles = []struct {
|
||||
}
|
||||
|
||||
func createTempDir(t *testing.T) string {
|
||||
tempdir, err := ioutil.TempDir(TestTempDir, "restic-test-")
|
||||
OK(t, err)
|
||||
tempdir, err := ioutil.TempDir(rtest.TestTempDir, "restic-test-")
|
||||
rtest.OK(t, err)
|
||||
|
||||
for _, test := range testFiles {
|
||||
file := filepath.Join(tempdir, test.name)
|
||||
dir := filepath.Dir(file)
|
||||
if dir != "." {
|
||||
OK(t, os.MkdirAll(dir, 0755))
|
||||
rtest.OK(t, os.MkdirAll(dir, 0755))
|
||||
}
|
||||
|
||||
f, err := os.Create(file)
|
||||
defer func() {
|
||||
OK(t, f.Close())
|
||||
rtest.OK(t, f.Close())
|
||||
}()
|
||||
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
_, err = f.Write(test.content)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
}
|
||||
|
||||
return tempdir
|
||||
@@ -50,8 +50,8 @@ func createTempDir(t *testing.T) string {
|
||||
func TestTree(t *testing.T) {
|
||||
dir := createTempDir(t)
|
||||
defer func() {
|
||||
if TestCleanupTempDirs {
|
||||
RemoveAll(t, dir)
|
||||
if rtest.TestCleanupTempDirs {
|
||||
rtest.RemoveAll(t, dir)
|
||||
}
|
||||
}()
|
||||
}
|
||||
@@ -67,11 +67,11 @@ var testNodes = []restic.Node{
|
||||
func TestNodeMarshal(t *testing.T) {
|
||||
for i, n := range testNodes {
|
||||
data, err := json.Marshal(&n)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
var node restic.Node
|
||||
err = json.Unmarshal(data, &node)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
if n.Name != node.Name {
|
||||
t.Fatalf("Node %d: Names are not equal, want: %q got: %q", i, n.Name, node.Name)
|
||||
@@ -81,16 +81,16 @@ func TestNodeMarshal(t *testing.T) {
|
||||
|
||||
func TestNodeComparison(t *testing.T) {
|
||||
fi, err := os.Lstat("tree_test.go")
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
node, err := restic.NodeFromFileInfo("tree_test.go", fi)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
n2 := *node
|
||||
Assert(t, node.Equals(n2), "nodes aren't equal")
|
||||
rtest.Assert(t, node.Equals(n2), "nodes aren't equal")
|
||||
|
||||
n2.Size--
|
||||
Assert(t, !node.Equals(n2), "nodes are equal")
|
||||
rtest.Assert(t, !node.Equals(n2), "nodes are equal")
|
||||
}
|
||||
|
||||
func TestLoadTree(t *testing.T) {
|
||||
@@ -100,16 +100,16 @@ func TestLoadTree(t *testing.T) {
|
||||
// save tree
|
||||
tree := restic.NewTree()
|
||||
id, err := repo.SaveTree(context.TODO(), tree)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
// save packs
|
||||
OK(t, repo.Flush())
|
||||
rtest.OK(t, repo.Flush())
|
||||
|
||||
// load tree again
|
||||
tree2, err := repo.LoadTree(context.TODO(), id)
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
Assert(t, tree.Equals(tree2),
|
||||
rtest.Assert(t, tree.Equals(tree2),
|
||||
"trees are not equal: want %v, got %v",
|
||||
tree, tree2)
|
||||
}
|
||||
|
@@ -12,7 +12,7 @@ import (
|
||||
"github.com/restic/restic/internal/pipe"
|
||||
"github.com/restic/restic/internal/repository"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
. "github.com/restic/restic/internal/test"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
"github.com/restic/restic/internal/walk"
|
||||
)
|
||||
|
||||
@@ -20,16 +20,16 @@ func TestWalkTree(t *testing.T) {
|
||||
repo, cleanup := repository.TestRepository(t)
|
||||
defer cleanup()
|
||||
|
||||
dirs, err := filepath.Glob(TestWalkerPath)
|
||||
OK(t, err)
|
||||
dirs, err := filepath.Glob(rtest.TestWalkerPath)
|
||||
rtest.OK(t, err)
|
||||
|
||||
// archive a few files
|
||||
arch := archiver.New(repo)
|
||||
sn, _, err := arch.Snapshot(context.TODO(), nil, dirs, nil, "localhost", nil, time.Now())
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
// flush repo, write all packs
|
||||
OK(t, repo.Flush())
|
||||
rtest.OK(t, repo.Flush())
|
||||
|
||||
// start tree walker
|
||||
treeJobs := make(chan walk.TreeJob)
|
||||
@@ -47,10 +47,10 @@ func TestWalkTree(t *testing.T) {
|
||||
for {
|
||||
// receive fs job
|
||||
fsJob, fsChOpen := <-fsJobs
|
||||
Assert(t, !fsChOpen || fsJob != nil,
|
||||
rtest.Assert(t, !fsChOpen || fsJob != nil,
|
||||
"received nil job from filesystem: %v %v", fsJob, fsChOpen)
|
||||
if fsJob != nil {
|
||||
OK(t, fsJob.Error())
|
||||
rtest.OK(t, fsJob.Error())
|
||||
}
|
||||
|
||||
var path string
|
||||
@@ -67,13 +67,13 @@ func TestWalkTree(t *testing.T) {
|
||||
treeJob, treeChOpen := <-treeJobs
|
||||
treeEntries := 1
|
||||
|
||||
OK(t, treeJob.Error)
|
||||
rtest.OK(t, treeJob.Error)
|
||||
|
||||
if treeJob.Tree != nil {
|
||||
treeEntries = len(treeJob.Tree.Nodes)
|
||||
}
|
||||
|
||||
Assert(t, fsChOpen == treeChOpen,
|
||||
rtest.Assert(t, fsChOpen == treeChOpen,
|
||||
"one channel closed too early: fsChOpen %v, treeChOpen %v",
|
||||
fsChOpen, treeChOpen)
|
||||
|
||||
@@ -81,10 +81,10 @@ func TestWalkTree(t *testing.T) {
|
||||
break
|
||||
}
|
||||
|
||||
Assert(t, filepath.Base(path) == filepath.Base(treeJob.Path),
|
||||
rtest.Assert(t, filepath.Base(path) == filepath.Base(treeJob.Path),
|
||||
"paths do not match: %q != %q", filepath.Base(path), filepath.Base(treeJob.Path))
|
||||
|
||||
Assert(t, fsEntries == treeEntries,
|
||||
rtest.Assert(t, fsEntries == treeEntries,
|
||||
"wrong number of entries: %v != %v", fsEntries, treeEntries)
|
||||
}
|
||||
}
|
||||
@@ -1340,14 +1340,14 @@ var walktreeTestItems = []string{
|
||||
}
|
||||
|
||||
func TestDelayedWalkTree(t *testing.T) {
|
||||
repodir, cleanup := Env(t, repoFixture)
|
||||
repodir, cleanup := rtest.Env(t, repoFixture)
|
||||
defer cleanup()
|
||||
|
||||
repo := repository.TestOpenLocal(t, repodir)
|
||||
OK(t, repo.LoadIndex(context.TODO()))
|
||||
rtest.OK(t, repo.LoadIndex(context.TODO()))
|
||||
|
||||
root, err := restic.ParseID("937a2f64f736c64ee700c6ab06f840c68c94799c288146a0e81e07f4c94254da")
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
dr := delayRepo{repo, 100 * time.Millisecond}
|
||||
|
||||
@@ -1370,14 +1370,14 @@ func TestDelayedWalkTree(t *testing.T) {
|
||||
}
|
||||
|
||||
func BenchmarkDelayedWalkTree(t *testing.B) {
|
||||
repodir, cleanup := Env(t, repoFixture)
|
||||
repodir, cleanup := rtest.Env(t, repoFixture)
|
||||
defer cleanup()
|
||||
|
||||
repo := repository.TestOpenLocal(t, repodir)
|
||||
OK(t, repo.LoadIndex(context.TODO()))
|
||||
rtest.OK(t, repo.LoadIndex(context.TODO()))
|
||||
|
||||
root, err := restic.ParseID("937a2f64f736c64ee700c6ab06f840c68c94799c288146a0e81e07f4c94254da")
|
||||
OK(t, err)
|
||||
rtest.OK(t, err)
|
||||
|
||||
dr := delayRepo{repo, 10 * time.Millisecond}
|
||||
|
||||
|
Reference in New Issue
Block a user