2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-26 14:56:29 +00:00

Remove all dot-imports

This commit is contained in:
Herbert 2017-10-02 15:06:39 +02:00
parent 1b5242b4f9
commit 3473c3f7b6
31 changed files with 598 additions and 601 deletions

View File

@ -13,7 +13,7 @@ import (
"github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/repository"
"github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/restic"
. "github.com/restic/restic/internal/test" "github.com/restic/restic/internal/test"
) )
const ( const (
@ -56,7 +56,7 @@ func waitForMount(t testing.TB, dir string) {
func testRunMount(t testing.TB, gopts GlobalOptions, dir string) { func testRunMount(t testing.TB, gopts GlobalOptions, dir string) {
opts := MountOptions{} opts := MountOptions{}
OK(t, runMount(opts, gopts, []string{dir})) test.OK(t, runMount(opts, gopts, []string{dir}))
} }
func testRunUmount(t testing.TB, gopts GlobalOptions, dir string) { func testRunUmount(t testing.TB, gopts GlobalOptions, dir string) {
@ -75,10 +75,10 @@ func testRunUmount(t testing.TB, gopts GlobalOptions, dir string) {
func listSnapshots(t testing.TB, dir string) []string { func listSnapshots(t testing.TB, dir string) []string {
snapshotsDir, err := os.Open(filepath.Join(dir, "snapshots")) snapshotsDir, err := os.Open(filepath.Join(dir, "snapshots"))
OK(t, err) test.OK(t, err)
names, err := snapshotsDir.Readdirnames(-1) names, err := snapshotsDir.Readdirnames(-1)
OK(t, err) test.OK(t, err)
OK(t, snapshotsDir.Close()) test.OK(t, snapshotsDir.Close())
return names return names
} }
@ -98,7 +98,7 @@ func checkSnapshots(t testing.TB, global GlobalOptions, repo *repository.Reposit
namesInSnapshots := listSnapshots(t, mountpoint) namesInSnapshots := listSnapshots(t, mountpoint)
t.Logf("found %v snapshots in fuse mount: %v", len(namesInSnapshots), namesInSnapshots) t.Logf("found %v snapshots in fuse mount: %v", len(namesInSnapshots), namesInSnapshots)
Assert(t, test.Assert(t,
expectedSnapshotsInFuseDir == len(namesInSnapshots), expectedSnapshotsInFuseDir == len(namesInSnapshots),
"Invalid number of snapshots: expected %d, got %d", expectedSnapshotsInFuseDir, len(namesInSnapshots)) "Invalid number of snapshots: expected %d, got %d", expectedSnapshotsInFuseDir, len(namesInSnapshots))
@ -119,7 +119,7 @@ func checkSnapshots(t testing.TB, global GlobalOptions, repo *repository.Reposit
for _, id := range snapshotIDs { for _, id := range snapshotIDs {
snapshot, err := restic.LoadSnapshot(context.TODO(), repo, id) snapshot, err := restic.LoadSnapshot(context.TODO(), repo, id)
OK(t, err) test.OK(t, err)
ts := snapshot.Time.Format(time.RFC3339) ts := snapshot.Time.Format(time.RFC3339)
present, ok := namesMap[ts] present, ok := namesMap[ts]
@ -143,12 +143,12 @@ func checkSnapshots(t testing.TB, global GlobalOptions, repo *repository.Reposit
} }
for name, present := range namesMap { for name, present := range namesMap {
Assert(t, present, "Directory %s is present in fuse dir but is not a snapshot", name) test.Assert(t, present, "Directory %s is present in fuse dir but is not a snapshot", name)
} }
} }
func TestMount(t *testing.T) { func TestMount(t *testing.T) {
if !RunFuseTest { if !test.RunFuseTest {
t.Skip("Skipping fuse tests") t.Skip("Skipping fuse tests")
} }
@ -158,19 +158,19 @@ func TestMount(t *testing.T) {
testRunInit(t, env.gopts) testRunInit(t, env.gopts)
repo, err := OpenRepository(env.gopts) repo, err := OpenRepository(env.gopts)
OK(t, err) test.OK(t, err)
// We remove the mountpoint now to check that cmdMount creates it // We remove the mountpoint now to check that cmdMount creates it
RemoveAll(t, env.mountpoint) test.RemoveAll(t, env.mountpoint)
checkSnapshots(t, env.gopts, repo, env.mountpoint, env.repo, []restic.ID{}, 0) checkSnapshots(t, env.gopts, repo, env.mountpoint, env.repo, []restic.ID{}, 0)
SetupTarTestFixture(t, env.testdata, filepath.Join("testdata", "backup-data.tar.gz")) test.SetupTarTestFixture(t, env.testdata, filepath.Join("testdata", "backup-data.tar.gz"))
// first backup // first backup
testRunBackup(t, []string{env.testdata}, BackupOptions{}, env.gopts) testRunBackup(t, []string{env.testdata}, BackupOptions{}, env.gopts)
snapshotIDs := testRunList(t, "snapshots", env.gopts) snapshotIDs := testRunList(t, "snapshots", env.gopts)
Assert(t, len(snapshotIDs) == 1, test.Assert(t, len(snapshotIDs) == 1,
"expected one snapshot, got %v", snapshotIDs) "expected one snapshot, got %v", snapshotIDs)
checkSnapshots(t, env.gopts, repo, env.mountpoint, env.repo, snapshotIDs, 2) checkSnapshots(t, env.gopts, repo, env.mountpoint, env.repo, snapshotIDs, 2)
@ -178,7 +178,7 @@ func TestMount(t *testing.T) {
// second backup, implicit incremental // second backup, implicit incremental
testRunBackup(t, []string{env.testdata}, BackupOptions{}, env.gopts) testRunBackup(t, []string{env.testdata}, BackupOptions{}, env.gopts)
snapshotIDs = testRunList(t, "snapshots", env.gopts) snapshotIDs = testRunList(t, "snapshots", env.gopts)
Assert(t, len(snapshotIDs) == 2, test.Assert(t, len(snapshotIDs) == 2,
"expected two snapshots, got %v", snapshotIDs) "expected two snapshots, got %v", snapshotIDs)
checkSnapshots(t, env.gopts, repo, env.mountpoint, env.repo, snapshotIDs, 3) checkSnapshots(t, env.gopts, repo, env.mountpoint, env.repo, snapshotIDs, 3)
@ -187,24 +187,24 @@ func TestMount(t *testing.T) {
bopts := BackupOptions{Parent: snapshotIDs[0].String()} bopts := BackupOptions{Parent: snapshotIDs[0].String()}
testRunBackup(t, []string{env.testdata}, bopts, env.gopts) testRunBackup(t, []string{env.testdata}, bopts, env.gopts)
snapshotIDs = testRunList(t, "snapshots", env.gopts) snapshotIDs = testRunList(t, "snapshots", env.gopts)
Assert(t, len(snapshotIDs) == 3, test.Assert(t, len(snapshotIDs) == 3,
"expected three snapshots, got %v", snapshotIDs) "expected three snapshots, got %v", snapshotIDs)
checkSnapshots(t, env.gopts, repo, env.mountpoint, env.repo, snapshotIDs, 4) checkSnapshots(t, env.gopts, repo, env.mountpoint, env.repo, snapshotIDs, 4)
} }
func TestMountSameTimestamps(t *testing.T) { func TestMountSameTimestamps(t *testing.T) {
if !RunFuseTest { if !test.RunFuseTest {
t.Skip("Skipping fuse tests") t.Skip("Skipping fuse tests")
} }
env, cleanup := withTestEnvironment(t) env, cleanup := withTestEnvironment(t)
defer cleanup() defer cleanup()
SetupTarTestFixture(t, env.base, filepath.Join("testdata", "repo-same-timestamps.tar.gz")) test.SetupTarTestFixture(t, env.base, filepath.Join("testdata", "repo-same-timestamps.tar.gz"))
repo, err := OpenRepository(env.gopts) repo, err := OpenRepository(env.gopts)
OK(t, err) test.OK(t, err)
ids := []restic.ID{ ids := []restic.ID{
restic.TestParseID("280303689e5027328889a06d718b729e96a1ce6ae9ef8290bff550459ae611ee"), restic.TestParseID("280303689e5027328889a06d718b729e96a1ce6ae9ef8290bff550459ae611ee"),

View File

@ -11,7 +11,7 @@ import (
"github.com/restic/restic/internal/options" "github.com/restic/restic/internal/options"
"github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/repository"
. "github.com/restic/restic/internal/test" "github.com/restic/restic/internal/test"
) )
type dirEntry struct { type dirEntry struct {
@ -174,14 +174,14 @@ type testEnvironment struct {
// withTestEnvironment creates a test environment and returns a cleanup // withTestEnvironment creates a test environment and returns a cleanup
// function which removes it. // function which removes it.
func withTestEnvironment(t testing.TB) (env *testEnvironment, cleanup func()) { func withTestEnvironment(t testing.TB) (env *testEnvironment, cleanup func()) {
if !RunIntegrationTest { if !test.RunIntegrationTest {
t.Skip("integration tests disabled") t.Skip("integration tests disabled")
} }
repository.TestUseLowSecurityKDFParameters(t) repository.TestUseLowSecurityKDFParameters(t)
tempdir, err := ioutil.TempDir(TestTempDir, "restic-test-") tempdir, err := ioutil.TempDir(test.TestTempDir, "restic-test-")
OK(t, err) test.OK(t, err)
env = &testEnvironment{ env = &testEnvironment{
base: tempdir, base: tempdir,
@ -191,17 +191,17 @@ func withTestEnvironment(t testing.TB) (env *testEnvironment, cleanup func()) {
mountpoint: filepath.Join(tempdir, "mount"), mountpoint: filepath.Join(tempdir, "mount"),
} }
OK(t, os.MkdirAll(env.mountpoint, 0700)) test.OK(t, os.MkdirAll(env.mountpoint, 0700))
OK(t, os.MkdirAll(env.testdata, 0700)) test.OK(t, os.MkdirAll(env.testdata, 0700))
OK(t, os.MkdirAll(env.cache, 0700)) test.OK(t, os.MkdirAll(env.cache, 0700))
OK(t, os.MkdirAll(env.repo, 0700)) test.OK(t, os.MkdirAll(env.repo, 0700))
env.gopts = GlobalOptions{ env.gopts = GlobalOptions{
Repo: env.repo, Repo: env.repo,
Quiet: true, Quiet: true,
CacheDir: env.cache, CacheDir: env.cache,
ctx: context.Background(), ctx: context.Background(),
password: TestPassword, password: test.TestPassword,
stdout: os.Stdout, stdout: os.Stdout,
stderr: os.Stderr, stderr: os.Stderr,
extended: make(options.Options), extended: make(options.Options),
@ -211,11 +211,11 @@ func withTestEnvironment(t testing.TB) (env *testEnvironment, cleanup func()) {
globalOptions = env.gopts globalOptions = env.gopts
cleanup = func() { cleanup = func() {
if !TestCleanupTempDirs { if !test.TestCleanupTempDirs {
t.Logf("leaving temporary directory %v used for test", tempdir) t.Logf("leaving temporary directory %v used for test", tempdir)
return return
} }
RemoveAll(t, tempdir) test.RemoveAll(t, tempdir)
} }
return env, cleanup return env, cleanup

View File

@ -17,13 +17,12 @@ import (
"testing" "testing"
"time" "time"
"github.com/restic/restic/internal/errors"
"github.com/restic/restic/internal/restic"
"github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/debug"
"github.com/restic/restic/internal/errors"
"github.com/restic/restic/internal/filter" "github.com/restic/restic/internal/filter"
"github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/repository"
. "github.com/restic/restic/internal/test" "github.com/restic/restic/internal/restic"
"github.com/restic/restic/internal/test"
) )
func parseIDsFromReader(t testing.TB, rd io.Reader) restic.IDs { func parseIDsFromReader(t testing.TB, rd io.Reader) restic.IDs {
@ -47,13 +46,13 @@ func testRunInit(t testing.TB, opts GlobalOptions) {
repository.TestUseLowSecurityKDFParameters(t) repository.TestUseLowSecurityKDFParameters(t)
restic.TestSetLockTimeout(t, 0) restic.TestSetLockTimeout(t, 0)
OK(t, runInit(opts, nil)) test.OK(t, runInit(opts, nil))
t.Logf("repository initialized at %v", opts.Repo) t.Logf("repository initialized at %v", opts.Repo)
} }
func testRunBackup(t testing.TB, target []string, opts BackupOptions, gopts GlobalOptions) { func testRunBackup(t testing.TB, target []string, opts BackupOptions, gopts GlobalOptions) {
t.Logf("backing up %v", target) t.Logf("backing up %v", target)
OK(t, runBackup(opts, gopts, target)) test.OK(t, runBackup(opts, gopts, target))
} }
func testRunList(t testing.TB, tpe string, opts GlobalOptions) restic.IDs { func testRunList(t testing.TB, tpe string, opts GlobalOptions) restic.IDs {
@ -63,7 +62,7 @@ func testRunList(t testing.TB, tpe string, opts GlobalOptions) restic.IDs {
globalOptions.stdout = os.Stdout globalOptions.stdout = os.Stdout
}() }()
OK(t, runList(opts, []string{tpe})) test.OK(t, runList(opts, []string{tpe}))
return parseIDsFromReader(t, buf) return parseIDsFromReader(t, buf)
} }
@ -78,7 +77,7 @@ func testRunRestoreLatest(t testing.TB, gopts GlobalOptions, dir string, paths [
Paths: paths, Paths: paths,
} }
OK(t, runRestore(opts, gopts, []string{"latest"})) test.OK(t, runRestore(opts, gopts, []string{"latest"}))
} }
func testRunRestoreExcludes(t testing.TB, gopts GlobalOptions, dir string, snapshotID restic.ID, excludes []string) { func testRunRestoreExcludes(t testing.TB, gopts GlobalOptions, dir string, snapshotID restic.ID, excludes []string) {
@ -87,7 +86,7 @@ func testRunRestoreExcludes(t testing.TB, gopts GlobalOptions, dir string, snaps
Exclude: excludes, Exclude: excludes,
} }
OK(t, runRestore(opts, gopts, []string{snapshotID.String()})) test.OK(t, runRestore(opts, gopts, []string{snapshotID.String()}))
} }
func testRunRestoreIncludes(t testing.TB, gopts GlobalOptions, dir string, snapshotID restic.ID, includes []string) { func testRunRestoreIncludes(t testing.TB, gopts GlobalOptions, dir string, snapshotID restic.ID, includes []string) {
@ -96,7 +95,7 @@ func testRunRestoreIncludes(t testing.TB, gopts GlobalOptions, dir string, snaps
Include: includes, Include: includes,
} }
OK(t, runRestore(opts, gopts, []string{snapshotID.String()})) test.OK(t, runRestore(opts, gopts, []string{snapshotID.String()}))
} }
func testRunCheck(t testing.TB, gopts GlobalOptions) { func testRunCheck(t testing.TB, gopts GlobalOptions) {
@ -104,7 +103,7 @@ func testRunCheck(t testing.TB, gopts GlobalOptions) {
ReadData: true, ReadData: true,
CheckUnused: true, CheckUnused: true,
} }
OK(t, runCheck(opts, gopts, nil)) test.OK(t, runCheck(opts, gopts, nil))
} }
func testRunCheckOutput(gopts GlobalOptions) (string, error) { func testRunCheckOutput(gopts GlobalOptions) (string, error) {
@ -129,7 +128,7 @@ func testRunRebuildIndex(t testing.TB, gopts GlobalOptions) {
globalOptions.stdout = os.Stdout globalOptions.stdout = os.Stdout
}() }()
OK(t, runRebuildIndex(gopts)) test.OK(t, runRebuildIndex(gopts))
} }
func testRunLs(t testing.TB, gopts GlobalOptions, snapshotID string) []string { func testRunLs(t testing.TB, gopts GlobalOptions, snapshotID string) []string {
@ -144,7 +143,7 @@ func testRunLs(t testing.TB, gopts GlobalOptions, snapshotID string) []string {
opts := LsOptions{} opts := LsOptions{}
OK(t, runLs(opts, gopts, []string{snapshotID})) test.OK(t, runLs(opts, gopts, []string{snapshotID}))
return strings.Split(string(buf.Bytes()), "\n") return strings.Split(string(buf.Bytes()), "\n")
} }
@ -160,7 +159,7 @@ func testRunFind(t testing.TB, wantJSON bool, gopts GlobalOptions, pattern strin
opts := FindOptions{} opts := FindOptions{}
OK(t, runFind(opts, gopts, []string{pattern})) test.OK(t, runFind(opts, gopts, []string{pattern}))
return buf.Bytes() return buf.Bytes()
} }
@ -176,10 +175,10 @@ func testRunSnapshots(t testing.TB, gopts GlobalOptions) (newest *Snapshot, snap
opts := SnapshotOptions{} opts := SnapshotOptions{}
OK(t, runSnapshots(opts, globalOptions, []string{})) test.OK(t, runSnapshots(opts, globalOptions, []string{}))
snapshots := []Snapshot{} snapshots := []Snapshot{}
OK(t, json.Unmarshal(buf.Bytes(), &snapshots)) test.OK(t, json.Unmarshal(buf.Bytes(), &snapshots))
snapmap = make(map[restic.ID]Snapshot, len(snapshots)) snapmap = make(map[restic.ID]Snapshot, len(snapshots))
for _, sn := range snapshots { for _, sn := range snapshots {
@ -193,11 +192,11 @@ func testRunSnapshots(t testing.TB, gopts GlobalOptions) (newest *Snapshot, snap
func testRunForget(t testing.TB, gopts GlobalOptions, args ...string) { func testRunForget(t testing.TB, gopts GlobalOptions, args ...string) {
opts := ForgetOptions{} opts := ForgetOptions{}
OK(t, runForget(opts, gopts, args)) test.OK(t, runForget(opts, gopts, args))
} }
func testRunPrune(t testing.TB, gopts GlobalOptions) { func testRunPrune(t testing.TB, gopts GlobalOptions) {
OK(t, runPrune(gopts)) test.OK(t, runPrune(gopts))
} }
func TestBackup(t *testing.T) { func TestBackup(t *testing.T) {
@ -210,18 +209,18 @@ func TestBackup(t *testing.T) {
t.Skipf("unable to find data file %q, skipping", datafile) t.Skipf("unable to find data file %q, skipping", datafile)
return return
} }
OK(t, err) test.OK(t, err)
OK(t, fd.Close()) test.OK(t, fd.Close())
testRunInit(t, env.gopts) testRunInit(t, env.gopts)
SetupTarTestFixture(t, env.testdata, datafile) test.SetupTarTestFixture(t, env.testdata, datafile)
opts := BackupOptions{} opts := BackupOptions{}
// first backup // first backup
testRunBackup(t, []string{env.testdata}, opts, env.gopts) testRunBackup(t, []string{env.testdata}, opts, env.gopts)
snapshotIDs := testRunList(t, "snapshots", env.gopts) snapshotIDs := testRunList(t, "snapshots", env.gopts)
Assert(t, len(snapshotIDs) == 1, test.Assert(t, len(snapshotIDs) == 1,
"expected one snapshot, got %v", snapshotIDs) "expected one snapshot, got %v", snapshotIDs)
testRunCheck(t, env.gopts) testRunCheck(t, env.gopts)
@ -230,7 +229,7 @@ func TestBackup(t *testing.T) {
// second backup, implicit incremental // second backup, implicit incremental
testRunBackup(t, []string{env.testdata}, opts, env.gopts) testRunBackup(t, []string{env.testdata}, opts, env.gopts)
snapshotIDs = testRunList(t, "snapshots", env.gopts) snapshotIDs = testRunList(t, "snapshots", env.gopts)
Assert(t, len(snapshotIDs) == 2, test.Assert(t, len(snapshotIDs) == 2,
"expected two snapshots, got %v", snapshotIDs) "expected two snapshots, got %v", snapshotIDs)
stat2 := dirStats(env.repo) stat2 := dirStats(env.repo)
@ -244,7 +243,7 @@ func TestBackup(t *testing.T) {
opts.Parent = snapshotIDs[0].String() opts.Parent = snapshotIDs[0].String()
testRunBackup(t, []string{env.testdata}, opts, env.gopts) testRunBackup(t, []string{env.testdata}, opts, env.gopts)
snapshotIDs = testRunList(t, "snapshots", env.gopts) snapshotIDs = testRunList(t, "snapshots", env.gopts)
Assert(t, len(snapshotIDs) == 3, test.Assert(t, len(snapshotIDs) == 3,
"expected three snapshots, got %v", snapshotIDs) "expected three snapshots, got %v", snapshotIDs)
stat3 := dirStats(env.repo) stat3 := dirStats(env.repo)
@ -258,7 +257,7 @@ func TestBackup(t *testing.T) {
restoredir := filepath.Join(env.base, fmt.Sprintf("restore%d", i)) restoredir := filepath.Join(env.base, fmt.Sprintf("restore%d", i))
t.Logf("restoring snapshot %v to %v", snapshotID.Str(), restoredir) t.Logf("restoring snapshot %v to %v", snapshotID.Str(), restoredir)
testRunRestore(t, env.gopts, restoredir, snapshotIDs[0]) testRunRestore(t, env.gopts, restoredir, snapshotIDs[0])
Assert(t, directoriesEqualContents(env.testdata, filepath.Join(restoredir, "testdata")), test.Assert(t, directoriesEqualContents(env.testdata, filepath.Join(restoredir, "testdata")),
"directories are not equal") "directories are not equal")
} }
@ -275,10 +274,10 @@ func TestBackupNonExistingFile(t *testing.T) {
t.Skipf("unable to find data file %q, skipping", datafile) t.Skipf("unable to find data file %q, skipping", datafile)
return return
} }
OK(t, err) test.OK(t, err)
OK(t, fd.Close()) test.OK(t, fd.Close())
SetupTarTestFixture(t, env.testdata, datafile) test.SetupTarTestFixture(t, env.testdata, datafile)
testRunInit(t, env.gopts) testRunInit(t, env.gopts)
globalOptions.stderr = ioutil.Discard globalOptions.stderr = ioutil.Discard
@ -309,10 +308,10 @@ func TestBackupMissingFile1(t *testing.T) {
t.Skipf("unable to find data file %q, skipping", datafile) t.Skipf("unable to find data file %q, skipping", datafile)
return return
} }
OK(t, err) test.OK(t, err)
OK(t, fd.Close()) test.OK(t, fd.Close())
SetupTarTestFixture(t, env.testdata, datafile) test.SetupTarTestFixture(t, env.testdata, datafile)
testRunInit(t, env.gopts) testRunInit(t, env.gopts)
globalOptions.stderr = ioutil.Discard globalOptions.stderr = ioutil.Discard
@ -331,7 +330,7 @@ func TestBackupMissingFile1(t *testing.T) {
t.Logf("in hook, removing test file testdata/0/0/9/37") t.Logf("in hook, removing test file testdata/0/0/9/37")
ranHook = true ranHook = true
OK(t, os.Remove(filepath.Join(env.testdata, "0", "0", "9", "37"))) test.OK(t, os.Remove(filepath.Join(env.testdata, "0", "0", "9", "37")))
}) })
opts := BackupOptions{} opts := BackupOptions{}
@ -339,7 +338,7 @@ func TestBackupMissingFile1(t *testing.T) {
testRunBackup(t, []string{env.testdata}, opts, env.gopts) testRunBackup(t, []string{env.testdata}, opts, env.gopts)
testRunCheck(t, env.gopts) testRunCheck(t, env.gopts)
Assert(t, ranHook, "hook did not run") test.Assert(t, ranHook, "hook did not run")
debug.RemoveHook("pipe.walk1") debug.RemoveHook("pipe.walk1")
} }
@ -353,10 +352,10 @@ func TestBackupMissingFile2(t *testing.T) {
t.Skipf("unable to find data file %q, skipping", datafile) t.Skipf("unable to find data file %q, skipping", datafile)
return return
} }
OK(t, err) test.OK(t, err)
OK(t, fd.Close()) test.OK(t, fd.Close())
SetupTarTestFixture(t, env.testdata, datafile) test.SetupTarTestFixture(t, env.testdata, datafile)
testRunInit(t, env.gopts) testRunInit(t, env.gopts)
@ -376,7 +375,7 @@ func TestBackupMissingFile2(t *testing.T) {
t.Logf("in hook, removing test file testdata/0/0/9/37") t.Logf("in hook, removing test file testdata/0/0/9/37")
ranHook = true ranHook = true
OK(t, os.Remove(filepath.Join(env.testdata, "0", "0", "9", "37"))) test.OK(t, os.Remove(filepath.Join(env.testdata, "0", "0", "9", "37")))
}) })
opts := BackupOptions{} opts := BackupOptions{}
@ -384,7 +383,7 @@ func TestBackupMissingFile2(t *testing.T) {
testRunBackup(t, []string{env.testdata}, opts, env.gopts) testRunBackup(t, []string{env.testdata}, opts, env.gopts)
testRunCheck(t, env.gopts) testRunCheck(t, env.gopts)
Assert(t, ranHook, "hook did not run") test.Assert(t, ranHook, "hook did not run")
debug.RemoveHook("pipe.walk2") debug.RemoveHook("pipe.walk2")
} }
@ -398,10 +397,10 @@ func TestBackupChangedFile(t *testing.T) {
t.Skipf("unable to find data file %q, skipping", datafile) t.Skipf("unable to find data file %q, skipping", datafile)
return return
} }
OK(t, err) test.OK(t, err)
OK(t, fd.Close()) test.OK(t, fd.Close())
SetupTarTestFixture(t, env.testdata, datafile) test.SetupTarTestFixture(t, env.testdata, datafile)
testRunInit(t, env.gopts) testRunInit(t, env.gopts)
@ -423,7 +422,7 @@ func TestBackupChangedFile(t *testing.T) {
t.Logf("in hook, modifying test file %v", modFile) t.Logf("in hook, modifying test file %v", modFile)
ranHook = true ranHook = true
OK(t, ioutil.WriteFile(modFile, []byte("modified"), 0600)) test.OK(t, ioutil.WriteFile(modFile, []byte("modified"), 0600))
}) })
opts := BackupOptions{} opts := BackupOptions{}
@ -431,7 +430,7 @@ func TestBackupChangedFile(t *testing.T) {
testRunBackup(t, []string{env.testdata}, opts, env.gopts) testRunBackup(t, []string{env.testdata}, opts, env.gopts)
testRunCheck(t, env.gopts) testRunCheck(t, env.gopts)
Assert(t, ranHook, "hook did not run") test.Assert(t, ranHook, "hook did not run")
debug.RemoveHook("archiver.SaveFile") debug.RemoveHook("archiver.SaveFile")
} }
@ -445,10 +444,10 @@ func TestBackupDirectoryError(t *testing.T) {
t.Skipf("unable to find data file %q, skipping", datafile) t.Skipf("unable to find data file %q, skipping", datafile)
return return
} }
OK(t, err) test.OK(t, err)
OK(t, fd.Close()) test.OK(t, fd.Close())
SetupTarTestFixture(t, env.testdata, datafile) test.SetupTarTestFixture(t, env.testdata, datafile)
testRunInit(t, env.gopts) testRunInit(t, env.gopts)
@ -472,22 +471,22 @@ func TestBackupDirectoryError(t *testing.T) {
t.Logf("in hook, removing test file %v", testdir) t.Logf("in hook, removing test file %v", testdir)
ranHook = true ranHook = true
OK(t, os.RemoveAll(testdir)) test.OK(t, os.RemoveAll(testdir))
}) })
testRunBackup(t, []string{filepath.Join(env.testdata, "0", "0")}, BackupOptions{}, env.gopts) testRunBackup(t, []string{filepath.Join(env.testdata, "0", "0")}, BackupOptions{}, env.gopts)
testRunCheck(t, env.gopts) testRunCheck(t, env.gopts)
Assert(t, ranHook, "hook did not run") test.Assert(t, ranHook, "hook did not run")
debug.RemoveHook("pipe.walk2") debug.RemoveHook("pipe.walk2")
snapshots := testRunList(t, "snapshots", env.gopts) snapshots := testRunList(t, "snapshots", env.gopts)
Assert(t, len(snapshots) > 0, test.Assert(t, len(snapshots) > 0,
"no snapshots found in repo (%v)", datafile) "no snapshots found in repo (%v)", datafile)
files := testRunLs(t, env.gopts, snapshots[0].String()) files := testRunLs(t, env.gopts, snapshots[0].String())
Assert(t, len(files) > 1, "snapshot is empty") test.Assert(t, len(files) > 1, "snapshot is empty")
} }
func includes(haystack []string, needle string) bool { func includes(haystack []string, needle string) bool {
@ -539,13 +538,13 @@ func TestBackupExclude(t *testing.T) {
for _, filename := range backupExcludeFilenames { for _, filename := range backupExcludeFilenames {
fp := filepath.Join(datadir, filename) fp := filepath.Join(datadir, filename)
OK(t, os.MkdirAll(filepath.Dir(fp), 0755)) test.OK(t, os.MkdirAll(filepath.Dir(fp), 0755))
f, err := os.Create(fp) f, err := os.Create(fp)
OK(t, err) test.OK(t, err)
fmt.Fprintf(f, filename) fmt.Fprintf(f, filename)
OK(t, f.Close()) test.OK(t, f.Close())
} }
snapshots := make(map[string]struct{}) snapshots := make(map[string]struct{})
@ -555,23 +554,23 @@ func TestBackupExclude(t *testing.T) {
testRunBackup(t, []string{datadir}, opts, env.gopts) testRunBackup(t, []string{datadir}, opts, env.gopts)
snapshots, snapshotID := lastSnapshot(snapshots, loadSnapshotMap(t, env.gopts)) snapshots, snapshotID := lastSnapshot(snapshots, loadSnapshotMap(t, env.gopts))
files := testRunLs(t, env.gopts, snapshotID) files := testRunLs(t, env.gopts, snapshotID)
Assert(t, includes(files, filepath.Join(string(filepath.Separator), "testdata", "foo.tar.gz")), test.Assert(t, includes(files, filepath.Join(string(filepath.Separator), "testdata", "foo.tar.gz")),
"expected file %q in first snapshot, but it's not included", "foo.tar.gz") "expected file %q in first snapshot, but it's not included", "foo.tar.gz")
opts.Excludes = []string{"*.tar.gz"} opts.Excludes = []string{"*.tar.gz"}
testRunBackup(t, []string{datadir}, opts, env.gopts) testRunBackup(t, []string{datadir}, opts, env.gopts)
snapshots, snapshotID = lastSnapshot(snapshots, loadSnapshotMap(t, env.gopts)) snapshots, snapshotID = lastSnapshot(snapshots, loadSnapshotMap(t, env.gopts))
files = testRunLs(t, env.gopts, snapshotID) files = testRunLs(t, env.gopts, snapshotID)
Assert(t, !includes(files, filepath.Join(string(filepath.Separator), "testdata", "foo.tar.gz")), test.Assert(t, !includes(files, filepath.Join(string(filepath.Separator), "testdata", "foo.tar.gz")),
"expected file %q not in first snapshot, but it's included", "foo.tar.gz") "expected file %q not in first snapshot, but it's included", "foo.tar.gz")
opts.Excludes = []string{"*.tar.gz", "private/secret"} opts.Excludes = []string{"*.tar.gz", "private/secret"}
testRunBackup(t, []string{datadir}, opts, env.gopts) testRunBackup(t, []string{datadir}, opts, env.gopts)
_, snapshotID = lastSnapshot(snapshots, loadSnapshotMap(t, env.gopts)) _, snapshotID = lastSnapshot(snapshots, loadSnapshotMap(t, env.gopts))
files = testRunLs(t, env.gopts, snapshotID) files = testRunLs(t, env.gopts, snapshotID)
Assert(t, !includes(files, filepath.Join(string(filepath.Separator), "testdata", "foo.tar.gz")), test.Assert(t, !includes(files, filepath.Join(string(filepath.Separator), "testdata", "foo.tar.gz")),
"expected file %q not in first snapshot, but it's included", "foo.tar.gz") "expected file %q not in first snapshot, but it's included", "foo.tar.gz")
Assert(t, !includes(files, filepath.Join(string(filepath.Separator), "testdata", "private", "secret", "passwords.txt")), test.Assert(t, !includes(files, filepath.Join(string(filepath.Separator), "testdata", "private", "secret", "passwords.txt")),
"expected file %q not in first snapshot, but it's included", "passwords.txt") "expected file %q not in first snapshot, but it's included", "passwords.txt")
} }
@ -612,7 +611,7 @@ func TestIncrementalBackup(t *testing.T) {
datadir := filepath.Join(env.base, "testdata") datadir := filepath.Join(env.base, "testdata")
testfile := filepath.Join(datadir, "testfile") testfile := filepath.Join(datadir, "testfile")
OK(t, appendRandomData(testfile, incrementalFirstWrite)) test.OK(t, appendRandomData(testfile, incrementalFirstWrite))
opts := BackupOptions{} opts := BackupOptions{}
@ -620,7 +619,7 @@ func TestIncrementalBackup(t *testing.T) {
testRunCheck(t, env.gopts) testRunCheck(t, env.gopts)
stat1 := dirStats(env.repo) stat1 := dirStats(env.repo)
OK(t, appendRandomData(testfile, incrementalSecondWrite)) test.OK(t, appendRandomData(testfile, incrementalSecondWrite))
testRunBackup(t, []string{datadir}, opts, env.gopts) testRunBackup(t, []string{datadir}, opts, env.gopts)
testRunCheck(t, env.gopts) testRunCheck(t, env.gopts)
@ -630,7 +629,7 @@ func TestIncrementalBackup(t *testing.T) {
} }
t.Logf("repository grown by %d bytes", stat2.size-stat1.size) t.Logf("repository grown by %d bytes", stat2.size-stat1.size)
OK(t, appendRandomData(testfile, incrementalThirdWrite)) test.OK(t, appendRandomData(testfile, incrementalThirdWrite))
testRunBackup(t, []string{datadir}, opts, env.gopts) testRunBackup(t, []string{datadir}, opts, env.gopts)
testRunCheck(t, env.gopts) testRunCheck(t, env.gopts)
@ -647,28 +646,28 @@ func TestBackupTags(t *testing.T) {
datafile := filepath.Join("testdata", "backup-data.tar.gz") datafile := filepath.Join("testdata", "backup-data.tar.gz")
testRunInit(t, env.gopts) testRunInit(t, env.gopts)
SetupTarTestFixture(t, env.testdata, datafile) test.SetupTarTestFixture(t, env.testdata, datafile)
opts := BackupOptions{} opts := BackupOptions{}
testRunBackup(t, []string{env.testdata}, opts, env.gopts) testRunBackup(t, []string{env.testdata}, opts, env.gopts)
testRunCheck(t, env.gopts) testRunCheck(t, env.gopts)
newest, _ := testRunSnapshots(t, env.gopts) newest, _ := testRunSnapshots(t, env.gopts)
Assert(t, newest != nil, "expected a new backup, got nil") test.Assert(t, newest != nil, "expected a new backup, got nil")
Assert(t, len(newest.Tags) == 0, test.Assert(t, len(newest.Tags) == 0,
"expected no tags, got %v", newest.Tags) "expected no tags, got %v", newest.Tags)
opts.Tags = []string{"NL"} opts.Tags = []string{"NL"}
testRunBackup(t, []string{env.testdata}, opts, env.gopts) testRunBackup(t, []string{env.testdata}, opts, env.gopts)
testRunCheck(t, env.gopts) testRunCheck(t, env.gopts)
newest, _ = testRunSnapshots(t, env.gopts) newest, _ = testRunSnapshots(t, env.gopts)
Assert(t, newest != nil, "expected a new backup, got nil") test.Assert(t, newest != nil, "expected a new backup, got nil")
Assert(t, len(newest.Tags) == 1 && newest.Tags[0] == "NL", test.Assert(t, len(newest.Tags) == 1 && newest.Tags[0] == "NL",
"expected one NL tag, got %v", newest.Tags) "expected one NL tag, got %v", newest.Tags)
} }
func testRunTag(t testing.TB, opts TagOptions, gopts GlobalOptions) { func testRunTag(t testing.TB, opts TagOptions, gopts GlobalOptions) {
OK(t, runTag(opts, gopts, []string{})) test.OK(t, runTag(opts, gopts, []string{}))
} }
func TestTag(t *testing.T) { func TestTag(t *testing.T) {
@ -677,68 +676,68 @@ func TestTag(t *testing.T) {
datafile := filepath.Join("testdata", "backup-data.tar.gz") datafile := filepath.Join("testdata", "backup-data.tar.gz")
testRunInit(t, env.gopts) testRunInit(t, env.gopts)
SetupTarTestFixture(t, env.testdata, datafile) test.SetupTarTestFixture(t, env.testdata, datafile)
testRunBackup(t, []string{env.testdata}, BackupOptions{}, env.gopts) testRunBackup(t, []string{env.testdata}, BackupOptions{}, env.gopts)
testRunCheck(t, env.gopts) testRunCheck(t, env.gopts)
newest, _ := testRunSnapshots(t, env.gopts) newest, _ := testRunSnapshots(t, env.gopts)
Assert(t, newest != nil, "expected a new backup, got nil") test.Assert(t, newest != nil, "expected a new backup, got nil")
Assert(t, len(newest.Tags) == 0, test.Assert(t, len(newest.Tags) == 0,
"expected no tags, got %v", newest.Tags) "expected no tags, got %v", newest.Tags)
Assert(t, newest.Original == nil, test.Assert(t, newest.Original == nil,
"expected original ID to be nil, got %v", newest.Original) "expected original ID to be nil, got %v", newest.Original)
originalID := *newest.ID originalID := *newest.ID
testRunTag(t, TagOptions{SetTags: []string{"NL"}}, env.gopts) testRunTag(t, TagOptions{SetTags: []string{"NL"}}, env.gopts)
testRunCheck(t, env.gopts) testRunCheck(t, env.gopts)
newest, _ = testRunSnapshots(t, env.gopts) newest, _ = testRunSnapshots(t, env.gopts)
Assert(t, newest != nil, "expected a new backup, got nil") test.Assert(t, newest != nil, "expected a new backup, got nil")
Assert(t, len(newest.Tags) == 1 && newest.Tags[0] == "NL", test.Assert(t, len(newest.Tags) == 1 && newest.Tags[0] == "NL",
"set failed, expected one NL tag, got %v", newest.Tags) "set failed, expected one NL tag, got %v", newest.Tags)
Assert(t, newest.Original != nil, "expected original snapshot id, got nil") test.Assert(t, newest.Original != nil, "expected original snapshot id, got nil")
Assert(t, *newest.Original == originalID, test.Assert(t, *newest.Original == originalID,
"expected original ID to be set to the first snapshot id") "expected original ID to be set to the first snapshot id")
testRunTag(t, TagOptions{AddTags: []string{"CH"}}, env.gopts) testRunTag(t, TagOptions{AddTags: []string{"CH"}}, env.gopts)
testRunCheck(t, env.gopts) testRunCheck(t, env.gopts)
newest, _ = testRunSnapshots(t, env.gopts) newest, _ = testRunSnapshots(t, env.gopts)
Assert(t, newest != nil, "expected a new backup, got nil") test.Assert(t, newest != nil, "expected a new backup, got nil")
Assert(t, len(newest.Tags) == 2 && newest.Tags[0] == "NL" && newest.Tags[1] == "CH", test.Assert(t, len(newest.Tags) == 2 && newest.Tags[0] == "NL" && newest.Tags[1] == "CH",
"add failed, expected CH,NL tags, got %v", newest.Tags) "add failed, expected CH,NL tags, got %v", newest.Tags)
Assert(t, newest.Original != nil, "expected original snapshot id, got nil") test.Assert(t, newest.Original != nil, "expected original snapshot id, got nil")
Assert(t, *newest.Original == originalID, test.Assert(t, *newest.Original == originalID,
"expected original ID to be set to the first snapshot id") "expected original ID to be set to the first snapshot id")
testRunTag(t, TagOptions{RemoveTags: []string{"NL"}}, env.gopts) testRunTag(t, TagOptions{RemoveTags: []string{"NL"}}, env.gopts)
testRunCheck(t, env.gopts) testRunCheck(t, env.gopts)
newest, _ = testRunSnapshots(t, env.gopts) newest, _ = testRunSnapshots(t, env.gopts)
Assert(t, newest != nil, "expected a new backup, got nil") test.Assert(t, newest != nil, "expected a new backup, got nil")
Assert(t, len(newest.Tags) == 1 && newest.Tags[0] == "CH", test.Assert(t, len(newest.Tags) == 1 && newest.Tags[0] == "CH",
"remove failed, expected one CH tag, got %v", newest.Tags) "remove failed, expected one CH tag, got %v", newest.Tags)
Assert(t, newest.Original != nil, "expected original snapshot id, got nil") test.Assert(t, newest.Original != nil, "expected original snapshot id, got nil")
Assert(t, *newest.Original == originalID, test.Assert(t, *newest.Original == originalID,
"expected original ID to be set to the first snapshot id") "expected original ID to be set to the first snapshot id")
testRunTag(t, TagOptions{AddTags: []string{"US", "RU"}}, env.gopts) testRunTag(t, TagOptions{AddTags: []string{"US", "RU"}}, env.gopts)
testRunTag(t, TagOptions{RemoveTags: []string{"CH", "US", "RU"}}, env.gopts) testRunTag(t, TagOptions{RemoveTags: []string{"CH", "US", "RU"}}, env.gopts)
testRunCheck(t, env.gopts) testRunCheck(t, env.gopts)
newest, _ = testRunSnapshots(t, env.gopts) newest, _ = testRunSnapshots(t, env.gopts)
Assert(t, newest != nil, "expected a new backup, got nil") test.Assert(t, newest != nil, "expected a new backup, got nil")
Assert(t, len(newest.Tags) == 0, test.Assert(t, len(newest.Tags) == 0,
"expected no tags, got %v", newest.Tags) "expected no tags, got %v", newest.Tags)
Assert(t, newest.Original != nil, "expected original snapshot id, got nil") test.Assert(t, newest.Original != nil, "expected original snapshot id, got nil")
Assert(t, *newest.Original == originalID, test.Assert(t, *newest.Original == originalID,
"expected original ID to be set to the first snapshot id") "expected original ID to be set to the first snapshot id")
// Check special case of removing all tags. // Check special case of removing all tags.
testRunTag(t, TagOptions{SetTags: []string{""}}, env.gopts) testRunTag(t, TagOptions{SetTags: []string{""}}, env.gopts)
testRunCheck(t, env.gopts) testRunCheck(t, env.gopts)
newest, _ = testRunSnapshots(t, env.gopts) newest, _ = testRunSnapshots(t, env.gopts)
Assert(t, newest != nil, "expected a new backup, got nil") test.Assert(t, newest != nil, "expected a new backup, got nil")
Assert(t, len(newest.Tags) == 0, test.Assert(t, len(newest.Tags) == 0,
"expected no tags, got %v", newest.Tags) "expected no tags, got %v", newest.Tags)
Assert(t, newest.Original != nil, "expected original snapshot id, got nil") test.Assert(t, newest.Original != nil, "expected original snapshot id, got nil")
Assert(t, *newest.Original == originalID, test.Assert(t, *newest.Original == originalID,
"expected original ID to be set to the first snapshot id") "expected original ID to be set to the first snapshot id")
} }
@ -750,7 +749,7 @@ func testRunKeyListOtherIDs(t testing.TB, gopts GlobalOptions) []string {
globalOptions.stdout = os.Stdout globalOptions.stdout = os.Stdout
}() }()
OK(t, runKey(gopts, []string{"list"})) test.OK(t, runKey(gopts, []string{"list"}))
scanner := bufio.NewScanner(buf) scanner := bufio.NewScanner(buf)
exp := regexp.MustCompile(`^ ([a-f0-9]+) `) exp := regexp.MustCompile(`^ ([a-f0-9]+) `)
@ -771,7 +770,7 @@ func testRunKeyAddNewKey(t testing.TB, newPassword string, gopts GlobalOptions)
testKeyNewPassword = "" testKeyNewPassword = ""
}() }()
OK(t, runKey(gopts, []string{"add"})) test.OK(t, runKey(gopts, []string{"add"}))
} }
func testRunKeyPasswd(t testing.TB, newPassword string, gopts GlobalOptions) { func testRunKeyPasswd(t testing.TB, newPassword string, gopts GlobalOptions) {
@ -780,13 +779,13 @@ func testRunKeyPasswd(t testing.TB, newPassword string, gopts GlobalOptions) {
testKeyNewPassword = "" testKeyNewPassword = ""
}() }()
OK(t, runKey(gopts, []string{"passwd"})) test.OK(t, runKey(gopts, []string{"passwd"}))
} }
func testRunKeyRemove(t testing.TB, gopts GlobalOptions, IDs []string) { func testRunKeyRemove(t testing.TB, gopts GlobalOptions, IDs []string) {
t.Logf("remove %d keys: %q\n", len(IDs), IDs) t.Logf("remove %d keys: %q\n", len(IDs), IDs)
for _, id := range IDs { for _, id := range IDs {
OK(t, runKey(gopts, []string{"remove", id})) test.OK(t, runKey(gopts, []string{"remove", id}))
} }
} }
@ -814,7 +813,7 @@ func TestKeyAddRemove(t *testing.T) {
env.gopts.password = passwordList[len(passwordList)-1] env.gopts.password = passwordList[len(passwordList)-1]
t.Logf("testing access with last password %q\n", env.gopts.password) t.Logf("testing access with last password %q\n", env.gopts.password)
OK(t, runKey(env.gopts, []string{"list"})) test.OK(t, runKey(env.gopts, []string{"list"}))
testRunCheck(t, env.gopts) testRunCheck(t, env.gopts)
} }
@ -847,10 +846,10 @@ func TestRestoreFilter(t *testing.T) {
testRunInit(t, env.gopts) testRunInit(t, env.gopts)
for _, test := range testfiles { for _, testFile := range testfiles {
p := filepath.Join(env.testdata, test.name) p := filepath.Join(env.testdata, testFile.name)
OK(t, os.MkdirAll(filepath.Dir(p), 0755)) test.OK(t, os.MkdirAll(filepath.Dir(p), 0755))
OK(t, appendRandomData(p, test.size)) test.OK(t, appendRandomData(p, testFile.size))
} }
opts := BackupOptions{} opts := BackupOptions{}
@ -862,20 +861,20 @@ func TestRestoreFilter(t *testing.T) {
// no restore filter should restore all files // no restore filter should restore all files
testRunRestore(t, env.gopts, filepath.Join(env.base, "restore0"), snapshotID) testRunRestore(t, env.gopts, filepath.Join(env.base, "restore0"), snapshotID)
for _, test := range testfiles { for _, testFile := range testfiles {
OK(t, testFileSize(filepath.Join(env.base, "restore0", "testdata", test.name), int64(test.size))) test.OK(t, testFileSize(filepath.Join(env.base, "restore0", "testdata", testFile.name), int64(testFile.size)))
} }
for i, pat := range []string{"*.c", "*.exe", "*", "*file3*"} { for i, pat := range []string{"*.c", "*.exe", "*", "*file3*"} {
base := filepath.Join(env.base, fmt.Sprintf("restore%d", i+1)) base := filepath.Join(env.base, fmt.Sprintf("restore%d", i+1))
testRunRestoreExcludes(t, env.gopts, base, snapshotID, []string{pat}) testRunRestoreExcludes(t, env.gopts, base, snapshotID, []string{pat})
for _, test := range testfiles { for _, testFile := range testfiles {
err := testFileSize(filepath.Join(base, "testdata", test.name), int64(test.size)) err := testFileSize(filepath.Join(base, "testdata", testFile.name), int64(testFile.size))
if ok, _ := filter.Match(pat, filepath.Base(test.name)); !ok { if ok, _ := filter.Match(pat, filepath.Base(testFile.name)); !ok {
OK(t, err) test.OK(t, err)
} else { } else {
Assert(t, os.IsNotExist(errors.Cause(err)), test.Assert(t, os.IsNotExist(errors.Cause(err)),
"expected %v to not exist in restore step %v, but it exists, err %v", test.name, i+1, err) "expected %v to not exist in restore step %v, but it exists, err %v", testFile.name, i+1, err)
} }
} }
} }
@ -889,8 +888,8 @@ 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))
OK(t, os.MkdirAll(filepath.Dir(p), 0755)) test.OK(t, os.MkdirAll(filepath.Dir(p), 0755))
OK(t, appendRandomData(p, uint(mrand.Intn(5<<21)))) test.OK(t, appendRandomData(p, uint(mrand.Intn(5<<21))))
} }
opts := BackupOptions{} opts := BackupOptions{}
@ -902,7 +901,7 @@ func TestRestore(t *testing.T) {
restoredir := filepath.Join(env.base, "restore") restoredir := filepath.Join(env.base, "restore")
testRunRestoreLatest(t, env.gopts, restoredir, nil, "") testRunRestoreLatest(t, env.gopts, restoredir, nil, "")
Assert(t, directoriesEqualContents(env.testdata, filepath.Join(restoredir, filepath.Base(env.testdata))), test.Assert(t, directoriesEqualContents(env.testdata, filepath.Join(restoredir, filepath.Base(env.testdata))),
"directories are not equal") "directories are not equal")
} }
@ -913,8 +912,8 @@ func TestRestoreLatest(t *testing.T) {
testRunInit(t, env.gopts) testRunInit(t, env.gopts)
p := filepath.Join(env.testdata, "testfile.c") p := filepath.Join(env.testdata, "testfile.c")
OK(t, os.MkdirAll(filepath.Dir(p), 0755)) test.OK(t, os.MkdirAll(filepath.Dir(p), 0755))
OK(t, appendRandomData(p, 100)) test.OK(t, appendRandomData(p, 100))
opts := BackupOptions{} opts := BackupOptions{}
@ -922,24 +921,24 @@ func TestRestoreLatest(t *testing.T) {
testRunCheck(t, env.gopts) testRunCheck(t, env.gopts)
os.Remove(p) os.Remove(p)
OK(t, appendRandomData(p, 101)) test.OK(t, appendRandomData(p, 101))
testRunBackup(t, []string{env.testdata}, opts, env.gopts) testRunBackup(t, []string{env.testdata}, opts, env.gopts)
testRunCheck(t, env.gopts) testRunCheck(t, env.gopts)
// Restore latest without any filters // Restore latest without any filters
testRunRestoreLatest(t, env.gopts, filepath.Join(env.base, "restore0"), nil, "") testRunRestoreLatest(t, env.gopts, filepath.Join(env.base, "restore0"), nil, "")
OK(t, testFileSize(filepath.Join(env.base, "restore0", "testdata", "testfile.c"), int64(101))) test.OK(t, testFileSize(filepath.Join(env.base, "restore0", "testdata", "testfile.c"), int64(101)))
// Setup test files in different directories backed up in different snapshots // Setup test files in different directories backed up in different snapshots
p1 := filepath.Join(env.testdata, "p1/testfile.c") p1 := filepath.Join(env.testdata, "p1/testfile.c")
OK(t, os.MkdirAll(filepath.Dir(p1), 0755)) test.OK(t, os.MkdirAll(filepath.Dir(p1), 0755))
OK(t, appendRandomData(p1, 102)) test.OK(t, appendRandomData(p1, 102))
testRunBackup(t, []string{filepath.Dir(p1)}, opts, env.gopts) testRunBackup(t, []string{filepath.Dir(p1)}, opts, env.gopts)
testRunCheck(t, env.gopts) testRunCheck(t, env.gopts)
p2 := filepath.Join(env.testdata, "p2/testfile.c") p2 := filepath.Join(env.testdata, "p2/testfile.c")
OK(t, os.MkdirAll(filepath.Dir(p2), 0755)) test.OK(t, os.MkdirAll(filepath.Dir(p2), 0755))
OK(t, appendRandomData(p2, 103)) test.OK(t, appendRandomData(p2, 103))
testRunBackup(t, []string{filepath.Dir(p2)}, opts, env.gopts) testRunBackup(t, []string{filepath.Dir(p2)}, opts, env.gopts)
testRunCheck(t, env.gopts) testRunCheck(t, env.gopts)
@ -947,16 +946,16 @@ func TestRestoreLatest(t *testing.T) {
p2rAbs := filepath.Join(env.base, "restore2", "p2/testfile.c") p2rAbs := filepath.Join(env.base, "restore2", "p2/testfile.c")
testRunRestoreLatest(t, env.gopts, filepath.Join(env.base, "restore1"), []string{filepath.Dir(p1)}, "") testRunRestoreLatest(t, env.gopts, filepath.Join(env.base, "restore1"), []string{filepath.Dir(p1)}, "")
OK(t, testFileSize(p1rAbs, int64(102))) test.OK(t, testFileSize(p1rAbs, int64(102)))
if _, err := os.Stat(p2rAbs); os.IsNotExist(errors.Cause(err)) { if _, err := os.Stat(p2rAbs); os.IsNotExist(errors.Cause(err)) {
Assert(t, os.IsNotExist(errors.Cause(err)), test.Assert(t, os.IsNotExist(errors.Cause(err)),
"expected %v to not exist in restore, but it exists, err %v", p2rAbs, err) "expected %v to not exist in restore, but it exists, err %v", p2rAbs, err)
} }
testRunRestoreLatest(t, env.gopts, filepath.Join(env.base, "restore2"), []string{filepath.Dir(p2)}, "") testRunRestoreLatest(t, env.gopts, filepath.Join(env.base, "restore2"), []string{filepath.Dir(p2)}, "")
OK(t, testFileSize(p2rAbs, int64(103))) test.OK(t, testFileSize(p2rAbs, int64(103)))
if _, err := os.Stat(p1rAbs); os.IsNotExist(errors.Cause(err)) { if _, err := os.Stat(p1rAbs); os.IsNotExist(errors.Cause(err)) {
Assert(t, os.IsNotExist(errors.Cause(err)), test.Assert(t, os.IsNotExist(errors.Cause(err)),
"expected %v to not exist in restore, but it exists, err %v", p1rAbs, err) "expected %v to not exist in restore, but it exists, err %v", p1rAbs, err)
} }
} }
@ -966,10 +965,10 @@ func TestRestoreWithPermissionFailure(t *testing.T) {
defer cleanup() defer cleanup()
datafile := filepath.Join("testdata", "repo-restore-permissions-test.tar.gz") datafile := filepath.Join("testdata", "repo-restore-permissions-test.tar.gz")
SetupTarTestFixture(t, env.base, datafile) test.SetupTarTestFixture(t, env.base, datafile)
snapshots := testRunList(t, "snapshots", env.gopts) snapshots := testRunList(t, "snapshots", env.gopts)
Assert(t, len(snapshots) > 0, test.Assert(t, len(snapshots) > 0,
"no snapshots found in repo (%v)", datafile) "no snapshots found in repo (%v)", datafile)
globalOptions.stderr = ioutil.Discard globalOptions.stderr = ioutil.Discard
@ -984,9 +983,9 @@ func TestRestoreWithPermissionFailure(t *testing.T) {
files := testRunLs(t, env.gopts, snapshots[0].String()) files := testRunLs(t, env.gopts, snapshots[0].String())
for _, filename := range files { for _, filename := range files {
fi, err := os.Lstat(filepath.Join(env.base, "restore", filename)) fi, err := os.Lstat(filepath.Join(env.base, "restore", filename))
OK(t, err) test.OK(t, err)
Assert(t, !isFile(fi) || fi.Size() > 0, test.Assert(t, !isFile(fi) || fi.Size() > 0,
"file %v restored, but filesize is 0", filename) "file %v restored, but filesize is 0", filename)
} }
} }
@ -1007,9 +1006,9 @@ func TestRestoreNoMetadataOnIgnoredIntermediateDirs(t *testing.T) {
testRunInit(t, env.gopts) testRunInit(t, env.gopts)
p := filepath.Join(env.testdata, "subdir1", "subdir2", "subdir3", "file.ext") p := filepath.Join(env.testdata, "subdir1", "subdir2", "subdir3", "file.ext")
OK(t, os.MkdirAll(filepath.Dir(p), 0755)) test.OK(t, os.MkdirAll(filepath.Dir(p), 0755))
OK(t, appendRandomData(p, 200)) test.OK(t, appendRandomData(p, 200))
OK(t, setZeroModTime(filepath.Join(env.testdata, "subdir1", "subdir2"))) test.OK(t, setZeroModTime(filepath.Join(env.testdata, "subdir1", "subdir2")))
opts := BackupOptions{} opts := BackupOptions{}
@ -1025,9 +1024,9 @@ func TestRestoreNoMetadataOnIgnoredIntermediateDirs(t *testing.T) {
f1 := filepath.Join(env.base, "restore0", "testdata", "subdir1", "subdir2") f1 := filepath.Join(env.base, "restore0", "testdata", "subdir1", "subdir2")
fi, err := os.Stat(f1) fi, err := os.Stat(f1)
OK(t, err) test.OK(t, err)
Assert(t, fi.ModTime() != time.Unix(0, 0), test.Assert(t, fi.ModTime() != time.Unix(0, 0),
"meta data of intermediate directory has been restore although it was ignored") "meta data of intermediate directory has been restore although it was ignored")
// restore with filter "*", this should restore meta data on everything. // restore with filter "*", this should restore meta data on everything.
@ -1035,9 +1034,9 @@ func TestRestoreNoMetadataOnIgnoredIntermediateDirs(t *testing.T) {
f2 := filepath.Join(env.base, "restore1", "testdata", "subdir1", "subdir2") f2 := filepath.Join(env.base, "restore1", "testdata", "subdir1", "subdir2")
fi, err = os.Stat(f2) fi, err = os.Stat(f2)
OK(t, err) test.OK(t, err)
Assert(t, fi.ModTime() == time.Unix(0, 0), test.Assert(t, fi.ModTime() == time.Unix(0, 0),
"meta data of intermediate directory hasn't been restore") "meta data of intermediate directory hasn't been restore")
} }
@ -1047,7 +1046,7 @@ func TestFind(t *testing.T) {
datafile := filepath.Join("testdata", "backup-data.tar.gz") datafile := filepath.Join("testdata", "backup-data.tar.gz")
testRunInit(t, env.gopts) testRunInit(t, env.gopts)
SetupTarTestFixture(t, env.testdata, datafile) test.SetupTarTestFixture(t, env.testdata, datafile)
opts := BackupOptions{} opts := BackupOptions{}
@ -1055,15 +1054,15 @@ func TestFind(t *testing.T) {
testRunCheck(t, env.gopts) testRunCheck(t, env.gopts)
results := testRunFind(t, false, env.gopts, "unexistingfile") results := testRunFind(t, false, env.gopts, "unexistingfile")
Assert(t, len(results) == 0, "unexisting file found in repo (%v)", datafile) test.Assert(t, len(results) == 0, "unexisting file found in repo (%v)", datafile)
results = testRunFind(t, false, env.gopts, "testfile") results = testRunFind(t, false, env.gopts, "testfile")
lines := strings.Split(string(results), "\n") lines := strings.Split(string(results), "\n")
Assert(t, len(lines) == 2, "expected one file found in repo (%v)", datafile) test.Assert(t, len(lines) == 2, "expected one file found in repo (%v)", datafile)
results = testRunFind(t, false, env.gopts, "testfile*") results = testRunFind(t, false, env.gopts, "testfile*")
lines = strings.Split(string(results), "\n") lines = strings.Split(string(results), "\n")
Assert(t, len(lines) == 4, "expected three files found in repo (%v)", datafile) test.Assert(t, len(lines) == 4, "expected three files found in repo (%v)", datafile)
} }
type testMatch struct { type testMatch struct {
@ -1087,7 +1086,7 @@ func TestFindJSON(t *testing.T) {
datafile := filepath.Join("testdata", "backup-data.tar.gz") datafile := filepath.Join("testdata", "backup-data.tar.gz")
testRunInit(t, env.gopts) testRunInit(t, env.gopts)
SetupTarTestFixture(t, env.testdata, datafile) test.SetupTarTestFixture(t, env.testdata, datafile)
opts := BackupOptions{} opts := BackupOptions{}
@ -1096,20 +1095,20 @@ func TestFindJSON(t *testing.T) {
results := testRunFind(t, true, env.gopts, "unexistingfile") results := testRunFind(t, true, env.gopts, "unexistingfile")
matches := []testMatches{} matches := []testMatches{}
OK(t, json.Unmarshal(results, &matches)) test.OK(t, json.Unmarshal(results, &matches))
Assert(t, len(matches) == 0, "expected no match in repo (%v)", datafile) test.Assert(t, len(matches) == 0, "expected no match in repo (%v)", datafile)
results = testRunFind(t, true, env.gopts, "testfile") results = testRunFind(t, true, env.gopts, "testfile")
OK(t, json.Unmarshal(results, &matches)) test.OK(t, json.Unmarshal(results, &matches))
Assert(t, len(matches) == 1, "expected a single snapshot in repo (%v)", datafile) test.Assert(t, len(matches) == 1, "expected a single snapshot in repo (%v)", datafile)
Assert(t, len(matches[0].Matches) == 1, "expected a single file to match (%v)", datafile) test.Assert(t, len(matches[0].Matches) == 1, "expected a single file to match (%v)", datafile)
Assert(t, matches[0].Hits == 1, "expected hits to show 1 match (%v)", datafile) test.Assert(t, matches[0].Hits == 1, "expected hits to show 1 match (%v)", datafile)
results = testRunFind(t, true, env.gopts, "testfile*") results = testRunFind(t, true, env.gopts, "testfile*")
OK(t, json.Unmarshal(results, &matches)) test.OK(t, json.Unmarshal(results, &matches))
Assert(t, len(matches) == 1, "expected a single snapshot in repo (%v)", datafile) test.Assert(t, len(matches) == 1, "expected a single snapshot in repo (%v)", datafile)
Assert(t, len(matches[0].Matches) == 3, "expected 3 files to match (%v)", datafile) test.Assert(t, len(matches[0].Matches) == 3, "expected 3 files to match (%v)", datafile)
Assert(t, matches[0].Hits == 3, "expected hits to show 3 matches (%v)", datafile) test.Assert(t, matches[0].Hits == 3, "expected hits to show 3 matches (%v)", datafile)
} }
func TestRebuildIndex(t *testing.T) { func TestRebuildIndex(t *testing.T) {
@ -1117,7 +1116,7 @@ func TestRebuildIndex(t *testing.T) {
defer cleanup() defer cleanup()
datafile := filepath.Join("..", "..", "internal", "checker", "testdata", "duplicate-packs-in-index-test-repo.tar.gz") datafile := filepath.Join("..", "..", "internal", "checker", "testdata", "duplicate-packs-in-index-test-repo.tar.gz")
SetupTarTestFixture(t, env.base, datafile) test.SetupTarTestFixture(t, env.base, datafile)
out, err := testRunCheckOutput(env.gopts) out, err := testRunCheckOutput(env.gopts)
if !strings.Contains(out, "contained in several indexes") { if !strings.Contains(out, "contained in several indexes") {
@ -1154,7 +1153,7 @@ func TestCheckRestoreNoLock(t *testing.T) {
defer cleanup() defer cleanup()
datafile := filepath.Join("testdata", "small-repo.tar.gz") datafile := filepath.Join("testdata", "small-repo.tar.gz")
SetupTarTestFixture(t, env.base, datafile) test.SetupTarTestFixture(t, env.base, datafile)
err := filepath.Walk(env.repo, func(p string, fi os.FileInfo, e error) error { err := filepath.Walk(env.repo, func(p string, fi os.FileInfo, e error) error {
if e != nil { if e != nil {
@ -1162,7 +1161,7 @@ func TestCheckRestoreNoLock(t *testing.T) {
} }
return os.Chmod(p, fi.Mode() & ^(os.FileMode(0222))) return os.Chmod(p, fi.Mode() & ^(os.FileMode(0222)))
}) })
OK(t, err) test.OK(t, err)
env.gopts.NoLock = true env.gopts.NoLock = true
@ -1186,24 +1185,24 @@ func TestPrune(t *testing.T) {
t.Skipf("unable to find data file %q, skipping", datafile) t.Skipf("unable to find data file %q, skipping", datafile)
return return
} }
OK(t, err) test.OK(t, err)
OK(t, fd.Close()) test.OK(t, fd.Close())
testRunInit(t, env.gopts) testRunInit(t, env.gopts)
SetupTarTestFixture(t, env.testdata, datafile) test.SetupTarTestFixture(t, env.testdata, datafile)
opts := BackupOptions{} opts := BackupOptions{}
testRunBackup(t, []string{filepath.Join(env.testdata, "0", "0")}, opts, env.gopts) testRunBackup(t, []string{filepath.Join(env.testdata, "0", "0")}, opts, env.gopts)
firstSnapshot := testRunList(t, "snapshots", env.gopts) firstSnapshot := testRunList(t, "snapshots", env.gopts)
Assert(t, len(firstSnapshot) == 1, test.Assert(t, len(firstSnapshot) == 1,
"expected one snapshot, got %v", firstSnapshot) "expected one snapshot, got %v", firstSnapshot)
testRunBackup(t, []string{filepath.Join(env.testdata, "0", "0", "2")}, opts, env.gopts) testRunBackup(t, []string{filepath.Join(env.testdata, "0", "0", "2")}, opts, env.gopts)
testRunBackup(t, []string{filepath.Join(env.testdata, "0", "0", "3")}, opts, env.gopts) testRunBackup(t, []string{filepath.Join(env.testdata, "0", "0", "3")}, opts, env.gopts)
snapshotIDs := testRunList(t, "snapshots", env.gopts) snapshotIDs := testRunList(t, "snapshots", env.gopts)
Assert(t, len(snapshotIDs) == 3, test.Assert(t, len(snapshotIDs) == 3,
"expected 3 snapshot, got %v", snapshotIDs) "expected 3 snapshot, got %v", snapshotIDs)
testRunForget(t, env.gopts, firstSnapshot[0].String()) testRunForget(t, env.gopts, firstSnapshot[0].String())
@ -1222,12 +1221,12 @@ func TestHardLink(t *testing.T) {
t.Skipf("unable to find data file %q, skipping", datafile) t.Skipf("unable to find data file %q, skipping", datafile)
return return
} }
OK(t, err) test.OK(t, err)
OK(t, fd.Close()) test.OK(t, fd.Close())
testRunInit(t, env.gopts) testRunInit(t, env.gopts)
SetupTarTestFixture(t, env.testdata, datafile) test.SetupTarTestFixture(t, env.testdata, datafile)
linkTests := createFileSetPerHardlink(env.testdata) linkTests := createFileSetPerHardlink(env.testdata)
@ -1236,7 +1235,7 @@ func TestHardLink(t *testing.T) {
// first backup // first backup
testRunBackup(t, []string{env.testdata}, opts, env.gopts) testRunBackup(t, []string{env.testdata}, opts, env.gopts)
snapshotIDs := testRunList(t, "snapshots", env.gopts) snapshotIDs := testRunList(t, "snapshots", env.gopts)
Assert(t, len(snapshotIDs) == 1, test.Assert(t, len(snapshotIDs) == 1,
"expected one snapshot, got %v", snapshotIDs) "expected one snapshot, got %v", snapshotIDs)
testRunCheck(t, env.gopts) testRunCheck(t, env.gopts)
@ -1246,11 +1245,11 @@ func TestHardLink(t *testing.T) {
restoredir := filepath.Join(env.base, fmt.Sprintf("restore%d", i)) restoredir := filepath.Join(env.base, fmt.Sprintf("restore%d", i))
t.Logf("restoring snapshot %v to %v", snapshotID.Str(), restoredir) t.Logf("restoring snapshot %v to %v", snapshotID.Str(), restoredir)
testRunRestore(t, env.gopts, restoredir, snapshotIDs[0]) testRunRestore(t, env.gopts, restoredir, snapshotIDs[0])
Assert(t, directoriesEqualContents(env.testdata, filepath.Join(restoredir, "testdata")), test.Assert(t, directoriesEqualContents(env.testdata, filepath.Join(restoredir, "testdata")),
"directories are not equal") "directories are not equal")
linkResults := createFileSetPerHardlink(filepath.Join(restoredir, "testdata")) linkResults := createFileSetPerHardlink(filepath.Join(restoredir, "testdata"))
Assert(t, linksEqual(linkTests, linkResults), test.Assert(t, linksEqual(linkTests, linkResults),
"links are not equal") "links are not equal")
} }

View File

@ -4,7 +4,7 @@ import (
"path/filepath" "path/filepath"
"testing" "testing"
. "github.com/restic/restic/internal/test" rtest "github.com/restic/restic/internal/test"
) )
func TestRestoreLocalLayout(t *testing.T) { func TestRestoreLocalLayout(t *testing.T) {
@ -24,7 +24,7 @@ func TestRestoreLocalLayout(t *testing.T) {
for _, test := range tests { for _, test := range tests {
datafile := filepath.Join("..", "..", "internal", "backend", "testdata", test.filename) datafile := filepath.Join("..", "..", "internal", "backend", "testdata", test.filename)
SetupTarTestFixture(t, env.base, datafile) rtest.SetupTarTestFixture(t, env.base, datafile)
env.gopts.extended["local.layout"] = test.layout env.gopts.extended["local.layout"] = test.layout
@ -35,7 +35,7 @@ func TestRestoreLocalLayout(t *testing.T) {
target := filepath.Join(env.base, "restore") target := filepath.Join(env.base, "restore")
testRunRestoreLatest(t, env.gopts, target, nil, "") testRunRestoreLatest(t, env.gopts, target, nil, "")
RemoveAll(t, filepath.Join(env.base, "repo")) rtest.RemoveAll(t, filepath.Join(env.base, "repo"))
RemoveAll(t, target) rtest.RemoveAll(t, target)
} }
} }

View File

@ -15,7 +15,7 @@ import (
"github.com/restic/restic/internal/crypto" "github.com/restic/restic/internal/crypto"
"github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/repository"
"github.com/restic/restic/internal/restic" "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" "github.com/restic/restic/internal/errors"
@ -40,14 +40,14 @@ func benchmarkChunkEncrypt(b testing.TB, buf, buf2 []byte, rd Rdr, key *crypto.K
break break
} }
OK(b, err) rtest.OK(b, err)
// reduce length of buf // 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) "invalid length: got %d, expected %d", len(chunk.Data), chunk.Length)
_, err = key.Encrypt(buf2, chunk.Data) _, 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) repo, cleanup := repository.TestRepository(b)
defer cleanup() defer cleanup()
data := Random(23, 10<<20) // 10MiB data := rtest.Random(23, 10<<20) // 10MiB
rd := bytes.NewReader(data) rd := bytes.NewReader(data)
buf := make([]byte, chunker.MaxSize) buf := make([]byte, chunker.MaxSize)
@ -87,7 +87,7 @@ func BenchmarkChunkEncryptParallel(b *testing.B) {
repo, cleanup := repository.TestRepository(b) repo, cleanup := repository.TestRepository(b)
defer cleanup() defer cleanup()
data := Random(23, 10<<20) // 10MiB data := rtest.Random(23, 10<<20) // 10MiB
buf := make([]byte, chunker.MaxSize) buf := make([]byte, chunker.MaxSize)
@ -108,14 +108,14 @@ func archiveDirectory(b testing.TB) {
arch := archiver.New(repo) arch := archiver.New(repo)
_, id, err := arch.Snapshot(context.TODO(), nil, []string{BenchArchiveDirectory}, nil, "localhost", nil, time.Now()) _, id, err := arch.Snapshot(context.TODO(), nil, []string{rtest.BenchArchiveDirectory}, nil, "localhost", nil, time.Now())
OK(b, err) rtest.OK(b, err)
b.Logf("snapshot archived as %v", id) b.Logf("snapshot archived as %v", id)
} }
func TestArchiveDirectory(t *testing.T) { func TestArchiveDirectory(t *testing.T) {
if BenchArchiveDirectory == "" { if rtest.BenchArchiveDirectory == "" {
t.Skip("benchdir not set, skipping TestArchiveDirectory") t.Skip("benchdir not set, skipping TestArchiveDirectory")
} }
@ -123,7 +123,7 @@ func TestArchiveDirectory(t *testing.T) {
} }
func BenchmarkArchiveDirectory(b *testing.B) { func BenchmarkArchiveDirectory(b *testing.B) {
if BenchArchiveDirectory == "" { if rtest.BenchArchiveDirectory == "" {
b.Skip("benchdir not set, skipping BenchmarkArchiveDirectory") b.Skip("benchdir not set, skipping BenchmarkArchiveDirectory")
} }
@ -144,7 +144,7 @@ func archiveWithDedup(t testing.TB) {
repo, cleanup := repository.TestRepository(t) repo, cleanup := repository.TestRepository(t)
defer cleanup() defer cleanup()
if BenchArchiveDirectory == "" { if rtest.BenchArchiveDirectory == "" {
t.Skip("benchdir not set, skipping TestArchiverDedup") t.Skip("benchdir not set, skipping TestArchiverDedup")
} }
@ -155,7 +155,7 @@ func archiveWithDedup(t testing.TB) {
} }
// archive a few files // 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()) t.Logf("archived snapshot %v", sn.ID().Str())
// get archive stats // get archive stats
@ -166,7 +166,7 @@ func archiveWithDedup(t testing.TB) {
cnt.before.packs, cnt.before.dataBlobs, cnt.before.treeBlobs) cnt.before.packs, cnt.before.dataBlobs, cnt.before.treeBlobs)
// archive the same files again, without parent snapshot // 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()) t.Logf("archived snapshot %v", sn2.ID().Str())
// get archive stats again // get archive stats again
@ -183,7 +183,7 @@ func archiveWithDedup(t testing.TB) {
} }
// archive the same files again, with a parent snapshot // 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()) t.Logf("archived snapshot %v, parent %v", sn3.ID().Str(), sn2.ID().Str())
// get archive stats again // get archive stats again
@ -246,18 +246,18 @@ func testParallelSaveWithDuplication(t *testing.T, seed int) {
} }
for _, errChan := range errChannels { for _, errChan := range errChannels {
OK(t, <-errChan) rtest.OK(t, <-errChan)
} }
OK(t, repo.Flush()) rtest.OK(t, repo.Flush())
OK(t, repo.SaveIndex(context.TODO())) rtest.OK(t, repo.SaveIndex(context.TODO()))
chkr := createAndInitChecker(t, repo) chkr := createAndInitChecker(t, repo)
assertNoUnreferencedPacks(t, chkr) assertNoUnreferencedPacks(t, chkr)
} }
func getRandomData(seed int, size int) []chunker.Chunk { func getRandomData(seed int, size int) []chunker.Chunk {
buf := Random(seed, size) buf := rtest.Random(seed, size)
var chunks []chunker.Chunk var chunks []chunker.Chunk
chunker := chunker.New(bytes.NewReader(buf), testPol) 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) go chkr.Packs(context.TODO(), errChan)
for err := range 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) repo, cleanup := repository.TestRepository(t)
defer cleanup() defer cleanup()
dir, cleanup := TempDir(t) dir, cleanup := rtest.TempDir(t)
defer cleanup() defer cleanup()
root := filepath.Join(dir, "root") 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)) rtest.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, "root", "testfile"), []byte("testfile2"), 0644))
defer chdir(t, root)() defer chdir(t, root)()
arch := archiver.New(repo) arch := archiver.New(repo)
sn, id, err := arch.Snapshot(context.TODO(), nil, []string{"testfile", filepath.Join("..", "testfile")}, nil, "localhost", nil, time.Now()) 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) t.Logf("snapshot archived as %v", id)
tree, err := repo.LoadTree(context.TODO(), *sn.Tree) tree, err := repo.LoadTree(context.TODO(), *sn.Tree)
OK(t, err) rtest.OK(t, err)
if len(tree.Nodes) != 2 { if len(tree.Nodes) != 2 {
t.Fatalf("tree has %d nodes, wanted 2: %v", len(tree.Nodes), tree.Nodes) t.Fatalf("tree has %d nodes, wanted 2: %v", len(tree.Nodes), tree.Nodes)

View File

@ -11,7 +11,7 @@ import (
"github.com/restic/restic/internal/backend/test" "github.com/restic/restic/internal/backend/test"
"github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/errors"
"github.com/restic/restic/internal/restic" "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 { func newAzureTestSuite(t testing.TB) *test.Suite {
@ -81,7 +81,7 @@ func newAzureTestSuite(t testing.TB) *test.Suite {
func TestBackendAzure(t *testing.T) { func TestBackendAzure(t *testing.T) {
defer func() { defer func() {
if t.Skipped() { if t.Skipped() {
SkipDisallowed(t, "restic/backend/azure.TestBackendAzure") rtest.SkipDisallowed(t, "restic/backend/azure.TestBackendAzure")
} }
}() }()

View File

@ -11,7 +11,7 @@ import (
"github.com/restic/restic/internal/backend/test" "github.com/restic/restic/internal/backend/test"
"github.com/restic/restic/internal/restic" "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 { func newB2TestSuite(t testing.TB) *test.Suite {
@ -83,7 +83,7 @@ func testVars(t testing.TB) {
func TestBackendB2(t *testing.T) { func TestBackendB2(t *testing.T) {
defer func() { defer func() {
if t.Skipped() { if t.Skipped() {
SkipDisallowed(t, "restic/backend/b2.TestBackendB2") rtest.SkipDisallowed(t, "restic/backend/b2.TestBackendB2")
} }
}() }()

View File

@ -11,7 +11,7 @@ import (
"github.com/restic/restic/internal/backend/test" "github.com/restic/restic/internal/backend/test"
"github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/errors"
"github.com/restic/restic/internal/restic" "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 { func newGSTestSuite(t testing.TB) *test.Suite {
@ -81,7 +81,7 @@ func newGSTestSuite(t testing.TB) *test.Suite {
func TestBackendGS(t *testing.T) { func TestBackendGS(t *testing.T) {
defer func() { defer func() {
if t.Skipped() { if t.Skipped() {
SkipDisallowed(t, "restic/backend/gs.TestBackendGS") rtest.SkipDisallowed(t, "restic/backend/gs.TestBackendGS")
} }
}() }()

View File

@ -9,11 +9,11 @@ import (
"testing" "testing"
"github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/restic"
. "github.com/restic/restic/internal/test" rtest "github.com/restic/restic/internal/test"
) )
func TestDefaultLayout(t *testing.T) { func TestDefaultLayout(t *testing.T) {
tempdir, cleanup := TempDir(t) tempdir, cleanup := rtest.TempDir(t)
defer cleanup() defer cleanup()
var tests = []struct { var tests = []struct {
@ -140,7 +140,7 @@ func TestDefaultLayout(t *testing.T) {
} }
func TestRESTLayout(t *testing.T) { func TestRESTLayout(t *testing.T) {
path, cleanup := TempDir(t) path, cleanup := rtest.TempDir(t)
defer cleanup() defer cleanup()
var tests = []struct { var tests = []struct {
@ -286,7 +286,7 @@ func TestRESTLayoutURLs(t *testing.T) {
} }
func TestS3LegacyLayout(t *testing.T) { func TestS3LegacyLayout(t *testing.T) {
path, cleanup := TempDir(t) path, cleanup := rtest.TempDir(t)
defer cleanup() defer cleanup()
var tests = []struct { var tests = []struct {
@ -354,7 +354,7 @@ func TestS3LegacyLayout(t *testing.T) {
} }
func TestDetectLayout(t *testing.T) { func TestDetectLayout(t *testing.T) {
path, cleanup := TempDir(t) path, cleanup := rtest.TempDir(t)
defer cleanup() defer cleanup()
var tests = []struct { var tests = []struct {
@ -369,7 +369,7 @@ func TestDetectLayout(t *testing.T) {
for _, test := range tests { for _, test := range tests {
for _, fs := range []Filesystem{fs, nil} { for _, fs := range []Filesystem{fs, nil} {
t.Run(fmt.Sprintf("%v/fs-%T", test.filename, fs), func(t *testing.T) { 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")) layout, err := DetectLayout(fs, filepath.Join(path, "repo"))
if err != nil { if err != nil {
@ -385,14 +385,14 @@ func TestDetectLayout(t *testing.T) {
t.Fatalf("want layout %v, got %v", test.want, layoutName) 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) { func TestParseLayout(t *testing.T) {
path, cleanup := TempDir(t) path, cleanup := rtest.TempDir(t)
defer cleanup() defer cleanup()
var tests = []struct { var tests = []struct {
@ -405,7 +405,7 @@ func TestParseLayout(t *testing.T) {
{"", "", "*backend.DefaultLayout"}, {"", "", "*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 { for _, test := range tests {
t.Run(test.layoutName, func(t *testing.T) { t.Run(test.layoutName, func(t *testing.T) {
@ -432,7 +432,7 @@ func TestParseLayout(t *testing.T) {
} }
func TestParseLayoutInvalid(t *testing.T) { func TestParseLayoutInvalid(t *testing.T) {
path, cleanup := TempDir(t) path, cleanup := rtest.TempDir(t)
defer cleanup() defer cleanup()
var invalidNames = []string{ var invalidNames = []string{

View File

@ -6,11 +6,11 @@ import (
"testing" "testing"
"github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/restic"
. "github.com/restic/restic/internal/test" rtest "github.com/restic/restic/internal/test"
) )
func TestLayout(t *testing.T) { func TestLayout(t *testing.T) {
path, cleanup := TempDir(t) path, cleanup := rtest.TempDir(t)
defer cleanup() defer cleanup()
var tests = []struct { var tests = []struct {
@ -33,7 +33,7 @@ func TestLayout(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.filename, func(t *testing.T) { 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") repo := filepath.Join(path, "repo")
be, err := Open(Config{ be, err := Open(Config{
@ -75,7 +75,7 @@ func TestLayout(t *testing.T) {
t.Errorf("Close() returned error %v", err) t.Errorf("Close() returned error %v", err)
} }
RemoveAll(t, filepath.Join(path, "repo")) rtest.RemoveAll(t, filepath.Join(path, "repo"))
}) })
} }
} }

View File

@ -9,14 +9,14 @@ import (
"github.com/restic/restic/internal/backend/local" "github.com/restic/restic/internal/backend/local"
"github.com/restic/restic/internal/backend/test" "github.com/restic/restic/internal/backend/test"
"github.com/restic/restic/internal/restic" "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 { func newTestSuite(t testing.TB) *test.Suite {
return &test.Suite{ return &test.Suite{
// NewConfig returns a config for a new temporary backend that will be used in tests. // NewConfig returns a config for a new temporary backend that will be used in tests.
NewConfig: func() (interface{}, error) { NewConfig: func() (interface{}, error) {
dir, err := ioutil.TempDir(TestTempDir, "restic-test-local-") dir, err := ioutil.TempDir(rtest.TestTempDir, "restic-test-local-")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -44,11 +44,11 @@ func newTestSuite(t testing.TB) *test.Suite {
// CleanupFn removes data created during the tests. // CleanupFn removes data created during the tests.
Cleanup: func(config interface{}) error { Cleanup: func(config interface{}) error {
cfg := config.(local.Config) cfg := config.(local.Config)
if !TestCleanupTempDirs { if !rtest.TestCleanupTempDirs {
t.Logf("leaving test backend dir at %v", cfg.Path) t.Logf("leaving test backend dir at %v", cfg.Path)
} }
RemoveAll(t, cfg.Path) rtest.RemoveAll(t, cfg.Path)
return nil return nil
}, },
} }
@ -119,7 +119,7 @@ func removeAll(t testing.TB, dir string) {
} }
func TestOpenNotExistingDirectory(t *testing.T) { func TestOpenNotExistingDirectory(t *testing.T) {
dir, cleanup := TempDir(t) dir, cleanup := rtest.TempDir(t)
defer cleanup() defer cleanup()
// local.Open must not create any files dirs in the repo // local.Open must not create any files dirs in the repo

View File

@ -13,7 +13,7 @@ import (
"github.com/restic/restic/internal/backend/rest" "github.com/restic/restic/internal/backend/rest"
"github.com/restic/restic/internal/backend/test" "github.com/restic/restic/internal/backend/test"
"github.com/restic/restic/internal/restic" "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() { 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{ return &test.Suite{
// NewConfig returns a config for a new temporary backend that will be used in tests. // NewConfig returns a config for a new temporary backend that will be used in tests.
NewConfig: func() (interface{}, error) { NewConfig: func() (interface{}, error) {
dir, err := ioutil.TempDir(TestTempDir, "restic-test-rest-") dir, err := ioutil.TempDir(rtest.TestTempDir, "restic-test-rest-")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -103,14 +103,14 @@ func newTestSuite(ctx context.Context, t testing.TB) *test.Suite {
func TestBackendREST(t *testing.T) { func TestBackendREST(t *testing.T) {
defer func() { defer func() {
if t.Skipped() { if t.Skipped() {
SkipDisallowed(t, "restic/backend/rest.TestBackendREST") rtest.SkipDisallowed(t, "restic/backend/rest.TestBackendREST")
} }
}() }()
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
dir, cleanup := TempDir(t) dir, cleanup := rtest.TempDir(t)
defer cleanup() defer cleanup()
cleanup = runRESTServer(ctx, t, dir) cleanup = runRESTServer(ctx, t, dir)
@ -123,7 +123,7 @@ func BenchmarkBackendREST(t *testing.B) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
dir, cleanup := TempDir(t) dir, cleanup := rtest.TempDir(t)
defer cleanup() defer cleanup()
cleanup = runRESTServer(ctx, t, dir) cleanup = runRESTServer(ctx, t, dir)

View File

@ -17,7 +17,7 @@ import (
"github.com/restic/restic/internal/backend/s3" "github.com/restic/restic/internal/backend/s3"
"github.com/restic/restic/internal/backend/test" "github.com/restic/restic/internal/backend/test"
"github.com/restic/restic/internal/restic" "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) { 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) { NewConfig: func() (interface{}, error) {
cfg := MinioTestConfig{} cfg := MinioTestConfig{}
cfg.tempdir, cfg.removeTempdir = TempDir(t) cfg.tempdir, cfg.removeTempdir = rtest.TempDir(t)
key, secret := newRandomCredentials(t) key, secret := newRandomCredentials(t)
cfg.stopServer = runMinio(ctx, t, cfg.tempdir, key, secret) 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) { func TestBackendMinio(t *testing.T) {
defer func() { defer func() {
if t.Skipped() { 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) { func TestBackendS3(t *testing.T) {
defer func() { defer func() {
if t.Skipped() { if t.Skipped() {
SkipDisallowed(t, "restic/backend/s3.TestBackendS3") rtest.SkipDisallowed(t, "restic/backend/s3.TestBackendS3")
} }
}() }()

View File

@ -8,7 +8,7 @@ import (
"github.com/restic/restic/internal/backend/sftp" "github.com/restic/restic/internal/backend/sftp"
"github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/restic"
. "github.com/restic/restic/internal/test" rtest "github.com/restic/restic/internal/test"
) )
func TestLayout(t *testing.T) { func TestLayout(t *testing.T) {
@ -16,7 +16,7 @@ func TestLayout(t *testing.T) {
t.Skip("sftp server binary not available") t.Skip("sftp server binary not available")
} }
path, cleanup := TempDir(t) path, cleanup := rtest.TempDir(t)
defer cleanup() defer cleanup()
var tests = []struct { var tests = []struct {
@ -39,7 +39,7 @@ func TestLayout(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.filename, func(t *testing.T) { 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") repo := filepath.Join(path, "repo")
be, err := sftp.Open(sftp.Config{ be, err := sftp.Open(sftp.Config{
@ -82,7 +82,7 @@ func TestLayout(t *testing.T) {
t.Errorf("Close() returned error %v", err) t.Errorf("Close() returned error %v", err)
} }
RemoveAll(t, filepath.Join(path, "repo")) rtest.RemoveAll(t, filepath.Join(path, "repo"))
}) })
} }
} }

View File

@ -12,12 +12,11 @@ import (
"github.com/restic/restic/internal/backend/test" "github.com/restic/restic/internal/backend/test"
"github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/errors"
"github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/restic"
rtest "github.com/restic/restic/internal/test"
. "github.com/restic/restic/internal/test"
) )
func findSFTPServerBinary() string { func findSFTPServerBinary() string {
for _, dir := range strings.Split(TestSFTPPath, ":") { for _, dir := range strings.Split(rtest.TestSFTPPath, ":") {
testpath := filepath.Join(dir, "sftp-server") testpath := filepath.Join(dir, "sftp-server")
_, err := os.Stat(testpath) _, err := os.Stat(testpath)
if !os.IsNotExist(errors.Cause(err)) { if !os.IsNotExist(errors.Cause(err)) {
@ -34,7 +33,7 @@ func newTestSuite(t testing.TB) *test.Suite {
return &test.Suite{ return &test.Suite{
// NewConfig returns a config for a new temporary backend that will be used in tests. // NewConfig returns a config for a new temporary backend that will be used in tests.
NewConfig: func() (interface{}, error) { NewConfig: func() (interface{}, error) {
dir, err := ioutil.TempDir(TestTempDir, "restic-test-sftp-") dir, err := ioutil.TempDir(rtest.TestTempDir, "restic-test-sftp-")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -63,11 +62,11 @@ func newTestSuite(t testing.TB) *test.Suite {
// CleanupFn removes data created during the tests. // CleanupFn removes data created during the tests.
Cleanup: func(config interface{}) error { Cleanup: func(config interface{}) error {
cfg := config.(sftp.Config) cfg := config.(sftp.Config)
if !TestCleanupTempDirs { if !rtest.TestCleanupTempDirs {
t.Logf("leaving test backend dir at %v", cfg.Path) t.Logf("leaving test backend dir at %v", cfg.Path)
} }
RemoveAll(t, cfg.Path) rtest.RemoveAll(t, cfg.Path)
return nil return nil
}, },
} }
@ -76,7 +75,7 @@ func newTestSuite(t testing.TB) *test.Suite {
func TestBackendSFTP(t *testing.T) { func TestBackendSFTP(t *testing.T) {
defer func() { defer func() {
if t.Skipped() { if t.Skipped() {
SkipDisallowed(t, "restic/backend/sftp.TestBackendSFTP") rtest.SkipDisallowed(t, "restic/backend/sftp.TestBackendSFTP")
} }
}() }()

View File

@ -7,12 +7,11 @@ import (
"testing" "testing"
"time" "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/swift"
"github.com/restic/restic/internal/backend/test" "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 { func newSwiftTestSuite(t testing.TB) *test.Suite {
@ -100,7 +99,7 @@ func newSwiftTestSuite(t testing.TB) *test.Suite {
func TestBackendSwift(t *testing.T) { func TestBackendSwift(t *testing.T) {
defer func() { defer func() {
if t.Skipped() { if t.Skipped() {
SkipDisallowed(t, "restic/backend/swift.TestBackendSwift") rtest.SkipDisallowed(t, "restic/backend/swift.TestBackendSwift")
} }
}() }()

View File

@ -9,7 +9,7 @@ import (
"github.com/restic/restic/internal/backend" "github.com/restic/restic/internal/backend"
"github.com/restic/restic/internal/backend/mem" "github.com/restic/restic/internal/backend/mem"
"github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/restic"
. "github.com/restic/restic/internal/test" rtest "github.com/restic/restic/internal/test"
) )
const KiB = 1 << 10 const KiB = 1 << 10
@ -19,14 +19,14 @@ func TestLoadAll(t *testing.T) {
b := mem.New() b := mem.New()
for i := 0; i < 20; i++ { 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) id := restic.Hash(data)
err := b.Save(context.TODO(), restic.Handle{Name: id.String(), Type: restic.DataFile}, bytes.NewReader(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()}) 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) { if len(buf) != len(data) {
t.Errorf("length of returned buffer does not match, want %d, got %d", len(data), len(buf)) 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() b := mem.New()
for i := 0; i < 20; i++ { 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) id := restic.Hash(data)
err := b.Save(context.TODO(), restic.Handle{Name: id.String(), Type: restic.DataFile}, bytes.NewReader(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()}) 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) { if len(buf) != len(data) {
t.Errorf("length of returned buffer does not match, want %d, got %d", len(data), len(buf)) 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() b := mem.New()
for i := 0; i < 20; i++ { 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) id := restic.Hash(data)
err := b.Save(context.TODO(), restic.Handle{Name: id.String(), Type: restic.DataFile}, bytes.NewReader(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()}) 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) { if len(buf) != len(data) {
t.Errorf("length of returned buffer does not match, want %d, got %d", len(data), len(buf)) t.Errorf("length of returned buffer does not match, want %d, got %d", len(data), len(buf))

View File

@ -7,7 +7,7 @@ import (
"testing" "testing"
"github.com/restic/restic/internal/crypto" "github.com/restic/restic/internal/crypto"
. "github.com/restic/restic/internal/test" rtest "github.com/restic/restic/internal/test"
"github.com/restic/chunker" "github.com/restic/chunker"
) )
@ -23,24 +23,24 @@ func TestEncryptDecrypt(t *testing.T) {
} }
for _, size := range tests { for _, size := range tests {
data := Random(42, size) data := rtest.Random(42, size)
buf := make([]byte, size+crypto.Extension) buf := make([]byte, size+crypto.Extension)
ciphertext, err := k.Encrypt(buf, data) ciphertext, err := k.Encrypt(buf, data)
OK(t, err) rtest.OK(t, err)
Assert(t, len(ciphertext) == len(data)+crypto.Extension, rtest.Assert(t, len(ciphertext) == len(data)+crypto.Extension,
"ciphertext length does not match: want %d, got %d", "ciphertext length does not match: want %d, got %d",
len(data)+crypto.Extension, len(ciphertext)) len(data)+crypto.Extension, len(ciphertext))
plaintext := make([]byte, len(ciphertext)) plaintext := make([]byte, len(ciphertext))
n, err := k.Decrypt(plaintext, ciphertext) n, err := k.Decrypt(plaintext, ciphertext)
OK(t, err) rtest.OK(t, err)
plaintext = plaintext[:n] 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", "plaintext length does not match: want %d, got %d",
len(data), len(plaintext)) len(data), len(plaintext))
Equals(t, plaintext, data) rtest.Equals(t, plaintext, data)
} }
} }
@ -50,21 +50,21 @@ func TestSmallBuffer(t *testing.T) {
size := 600 size := 600
data := make([]byte, size) data := make([]byte, size)
_, err := io.ReadFull(rand.Reader, data) _, err := io.ReadFull(rand.Reader, data)
OK(t, err) rtest.OK(t, err)
ciphertext := make([]byte, size/2) ciphertext := make([]byte, size/2)
ciphertext, err = k.Encrypt(ciphertext, data) ciphertext, err = k.Encrypt(ciphertext, data)
// this must extend the slice // 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", "expected extended slice, but capacity is only %d bytes",
cap(ciphertext)) cap(ciphertext))
// check for the correct plaintext // check for the correct plaintext
plaintext := make([]byte, len(ciphertext)) plaintext := make([]byte, len(ciphertext))
n, err := k.Decrypt(plaintext, ciphertext) n, err := k.Decrypt(plaintext, ciphertext)
OK(t, err) rtest.OK(t, err)
plaintext = plaintext[:n] plaintext = plaintext[:n]
Assert(t, bytes.Equal(plaintext, data), rtest.Assert(t, bytes.Equal(plaintext, data),
"wrong plaintext returned") "wrong plaintext returned")
} }
@ -74,18 +74,18 @@ func TestSameBuffer(t *testing.T) {
size := 600 size := 600
data := make([]byte, size) data := make([]byte, size)
_, err := io.ReadFull(rand.Reader, data) _, err := io.ReadFull(rand.Reader, data)
OK(t, err) rtest.OK(t, err)
ciphertext := make([]byte, 0, size+crypto.Extension) ciphertext := make([]byte, 0, size+crypto.Extension)
ciphertext, err = k.Encrypt(ciphertext, data) ciphertext, err = k.Encrypt(ciphertext, data)
OK(t, err) rtest.OK(t, err)
// use the same buffer for decryption // use the same buffer for decryption
n, err := k.Decrypt(ciphertext, ciphertext) n, err := k.Decrypt(ciphertext, ciphertext)
OK(t, err) rtest.OK(t, err)
ciphertext = ciphertext[:n] ciphertext = ciphertext[:n]
Assert(t, bytes.Equal(ciphertext, data), rtest.Assert(t, bytes.Equal(ciphertext, data),
"wrong plaintext returned") "wrong plaintext returned")
} }
@ -95,20 +95,20 @@ func TestCornerCases(t *testing.T) {
// nil plaintext should encrypt to the empty string // nil plaintext should encrypt to the empty string
// nil ciphertext should allocate a new slice for the ciphertext // nil ciphertext should allocate a new slice for the ciphertext
c, err := k.Encrypt(nil, nil) 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", "wrong length returned for ciphertext, expected 0, got %d",
len(c)) len(c))
// this should decrypt to nil // this should decrypt to nil
n, err := k.Decrypt(nil, c) n, err := k.Decrypt(nil, c)
OK(t, err) rtest.OK(t, err)
Equals(t, 0, n) rtest.Equals(t, 0, n)
// test encryption for same slice, this should return an error // test encryption for same slice, this should return an error
_, err = k.Encrypt(c, c) _, err = k.Encrypt(c, c)
Equals(t, crypto.ErrInvalidCiphertext, err) rtest.Equals(t, crypto.ErrInvalidCiphertext, err)
} }
func TestLargeEncrypt(t *testing.T) { 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} { for _, size := range []int{chunker.MaxSize, chunker.MaxSize + 1, chunker.MaxSize + 1<<20} {
data := make([]byte, size) data := make([]byte, size)
_, err := io.ReadFull(rand.Reader, data) _, err := io.ReadFull(rand.Reader, data)
OK(t, err) rtest.OK(t, err)
ciphertext, err := k.Encrypt(make([]byte, size+crypto.Extension), data) ciphertext, err := k.Encrypt(make([]byte, size+crypto.Extension), data)
OK(t, err) rtest.OK(t, err)
plaintext, err := k.Decrypt([]byte{}, ciphertext) 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++ { for i := 0; i < b.N; i++ {
_, err := k.Encrypt(buf, data) _, 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 := make([]byte, size+crypto.Extension)
ciphertext, err := k.Encrypt(ciphertext, data) ciphertext, err := k.Encrypt(ciphertext, data)
OK(b, err) rtest.OK(b, err)
b.ResetTimer() b.ResetTimer()
b.SetBytes(int64(size)) b.SetBytes(int64(size))
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
_, err = k.Decrypt(plaintext, ciphertext) _, err = k.Decrypt(plaintext, ciphertext)
OK(b, err) rtest.OK(b, err)
} }
} }

View File

@ -17,7 +17,7 @@ import (
"bazil.org/fuse" "bazil.org/fuse"
"bazil.org/fuse/fs" "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) { 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{ resp := &fuse.ReadResponse{
Data: data, 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) { 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 { func loadFirstSnapshot(t testing.TB, repo restic.Repository) *restic.Snapshot {
id := firstSnapshotID(t, repo) id := firstSnapshotID(t, repo)
sn, err := restic.LoadSnapshot(context.TODO(), repo, id) sn, err := restic.LoadSnapshot(context.TODO(), repo, id)
OK(t, err) rtest.OK(t, err)
return sn return sn
} }
func loadTree(t testing.TB, repo restic.Repository, id restic.ID) *restic.Tree { func loadTree(t testing.TB, repo restic.Repository, id restic.ID) *restic.Tree {
tree, err := repo.LoadTree(context.TODO(), id) tree, err := repo.LoadTree(context.TODO(), id)
OK(t, err) rtest.OK(t, err)
return tree return tree
} }
@ -64,7 +64,7 @@ func TestFuseFile(t *testing.T) {
defer cancel() defer cancel()
timestamp, err := time.Parse(time.RFC3339, "2017-01-24T10:42:56+01:00") 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) restic.TestCreateSnapshot(t, repo, timestamp, 2, 0.1)
sn := loadFirstSnapshot(t, repo) sn := loadFirstSnapshot(t, repo)
@ -82,12 +82,12 @@ func TestFuseFile(t *testing.T) {
) )
for _, id := range content { for _, id := range content {
size, err := repo.LookupBlobSize(id, restic.DataBlob) size, err := repo.LookupBlobSize(id, restic.DataBlob)
OK(t, err) rtest.OK(t, err)
filesize += uint64(size) filesize += uint64(size)
buf := restic.NewBlobBuffer(int(size)) buf := restic.NewBlobBuffer(int(size))
n, err := repo.LoadBlob(context.TODO(), restic.DataBlob, id, buf) n, err := repo.LoadBlob(context.TODO(), restic.DataBlob, id, buf)
OK(t, err) rtest.OK(t, err)
if uint(n) != size { if uint(n) != size {
t.Fatalf("not enough bytes read for id %v: want %v, got %v", id.Str(), size, n) 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") inode := fs.GenerateDynamicInode(1, "foo")
f, err := newFile(context.TODO(), root, inode, node) f, err := newFile(context.TODO(), root, inode, node)
OK(t, err) rtest.OK(t, err)
attr := fuse.Attr{} attr := fuse.Attr{}
OK(t, f.Attr(ctx, &attr)) rtest.OK(t, f.Attr(ctx, &attr))
Equals(t, inode, attr.Inode) rtest.Equals(t, inode, attr.Inode)
Equals(t, node.Mode, attr.Mode) rtest.Equals(t, node.Mode, attr.Mode)
Equals(t, node.Size, attr.Size) rtest.Equals(t, node.Size, attr.Size)
Equals(t, (node.Size/uint64(attr.BlockSize))+1, attr.Blocks) rtest.Equals(t, (node.Size/uint64(attr.BlockSize))+1, attr.Blocks)
for i := 0; i < 200; i++ { for i := 0; i < 200; i++ {
offset := rand.Intn(int(filesize)) 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))
} }

View File

@ -14,7 +14,7 @@ import (
"github.com/restic/restic/internal/crypto" "github.com/restic/restic/internal/crypto"
"github.com/restic/restic/internal/pack" "github.com/restic/restic/internal/pack"
"github.com/restic/restic/internal/restic" "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} 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 { for _, l := range lengths {
b := make([]byte, l) b := make([]byte, l)
_, err := io.ReadFull(rand.Reader, b) _, err := io.ReadFull(rand.Reader, b)
OK(t, err) rtest.OK(t, err)
h := sha256.Sum256(b) h := sha256.Sum256(b)
bufs = append(bufs, Buf{data: b, id: h}) 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() _, err := p.Finalize()
OK(t, err) rtest.OK(t, err)
packData := p.Writer().(*bytes.Buffer).Bytes() packData := p.Writer().(*bytes.Buffer).Bytes()
return bufs, packData, p.Size() 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) written += restic.CiphertextLength(headerSize)
// check length // check length
Equals(t, uint(written), packSize) rtest.Equals(t, uint(written), packSize)
// read and parse it again // read and parse it again
entries, err := pack.List(k, rd, int64(packSize)) entries, err := pack.List(k, rd, int64(packSize))
OK(t, err) rtest.OK(t, err)
Equals(t, len(entries), len(bufs)) rtest.Equals(t, len(entries), len(bufs))
var buf []byte var buf []byte
for i, b := range bufs { for i, b := range bufs {
e := entries[i] e := entries[i]
Equals(t, b.id, e.ID) rtest.Equals(t, b.id, e.ID)
if len(buf) < int(e.Length) { if len(buf) < int(e.Length) {
buf = make([]byte, int(e.Length)) buf = make([]byte, int(e.Length))
} }
buf = buf[:int(e.Length)] buf = buf[:int(e.Length)]
n, err := rd.ReadAt(buf, int64(e.Offset)) n, err := rd.ReadAt(buf, int64(e.Offset))
OK(t, err) rtest.OK(t, err)
buf = buf[:n] 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) "data for blob %v doesn't match", i)
} }
} }
@ -90,7 +90,7 @@ func TestCreatePack(t *testing.T) {
k := crypto.NewRandomKey() k := crypto.NewRandomKey()
bufs, packData, packSize := newPack(t, k, testLens) 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) verifyBlobs(t, bufs, k, bytes.NewReader(packData), packSize)
} }
@ -106,14 +106,14 @@ func TestBlobTypeJSON(t *testing.T) {
for _, test := range blobTypeJSON { for _, test := range blobTypeJSON {
// test serialize // test serialize
buf, err := json.Marshal(test.t) buf, err := json.Marshal(test.t)
OK(t, err) rtest.OK(t, err)
Equals(t, test.res, string(buf)) rtest.Equals(t, test.res, string(buf))
// test unserialize // test unserialize
var v restic.BlobType var v restic.BlobType
err = json.Unmarshal([]byte(test.res), &v) err = json.Unmarshal([]byte(test.res), &v)
OK(t, err) rtest.OK(t, err)
Equals(t, test.t, v) rtest.Equals(t, test.t, v)
} }
} }
@ -127,7 +127,7 @@ func TestUnpackReadSeeker(t *testing.T) {
id := restic.Hash(packData) id := restic.Hash(packData)
handle := restic.Handle{Type: restic.DataFile, Name: id.String()} 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) verifyBlobs(t, bufs, k, restic.ReaderAt(b, handle), packSize)
} }
@ -140,6 +140,6 @@ func TestShortPack(t *testing.T) {
id := restic.Hash(packData) id := restic.Hash(packData)
handle := restic.Handle{Type: restic.DataFile, Name: id.String()} 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) verifyBlobs(t, bufs, k, restic.ReaderAt(b, handle), packSize)
} }

View File

@ -12,7 +12,7 @@ import (
"github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/debug"
"github.com/restic/restic/internal/pipe" "github.com/restic/restic/internal/pipe"
. "github.com/restic/restic/internal/test" rtest "github.com/restic/restic/internal/test"
) )
type stats struct { type stats struct {
@ -27,7 +27,7 @@ func statPath(path string) (stats, error) {
var s stats var s stats
// count files and directories with filepath.Walk() // 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 { if fi == nil {
return err return err
} }
@ -47,20 +47,20 @@ func statPath(path string) (stats, error) {
const maxWorkers = 100 const maxWorkers = 100
func TestPipelineWalkerWithSplit(t *testing.T) { func TestPipelineWalkerWithSplit(t *testing.T) {
if TestWalkerPath == "" { if rtest.TestWalkerPath == "" {
t.Skipf("walkerpath not set, skipping TestPipelineWalker") t.Skipf("walkerpath not set, skipping TestPipelineWalker")
} }
var err error var err error
if !filepath.IsAbs(TestWalkerPath) { if !filepath.IsAbs(rtest.TestWalkerPath) {
TestWalkerPath, err = filepath.Abs(TestWalkerPath) rtest.TestWalkerPath, err = filepath.Abs(rtest.TestWalkerPath)
OK(t, err) rtest.OK(t, err)
} }
before, err := statPath(TestWalkerPath) before, err := statPath(rtest.TestWalkerPath)
OK(t, err) 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) before.dirs, before.files)
// account for top level dir // account for top level dir
@ -128,7 +128,7 @@ func TestPipelineWalkerWithSplit(t *testing.T) {
}() }()
resCh := make(chan pipe.Result, 1) 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 // wait for all workers to terminate
wg.Wait() wg.Wait()
@ -136,14 +136,14 @@ func TestPipelineWalkerWithSplit(t *testing.T) {
// wait for top-level blob // wait for top-level blob
<-resCh <-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) 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) { func TestPipelineWalker(t *testing.T) {
if TestWalkerPath == "" { if rtest.TestWalkerPath == "" {
t.Skipf("walkerpath not set, skipping TestPipelineWalker") t.Skipf("walkerpath not set, skipping TestPipelineWalker")
} }
@ -151,15 +151,15 @@ func TestPipelineWalker(t *testing.T) {
defer cancel() defer cancel()
var err error var err error
if !filepath.IsAbs(TestWalkerPath) { if !filepath.IsAbs(rtest.TestWalkerPath) {
TestWalkerPath, err = filepath.Abs(TestWalkerPath) rtest.TestWalkerPath, err = filepath.Abs(rtest.TestWalkerPath)
OK(t, err) rtest.OK(t, err)
} }
before, err := statPath(TestWalkerPath) before, err := statPath(rtest.TestWalkerPath)
OK(t, err) 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) before.dirs, before.files)
// account for top level dir // account for top level dir
@ -177,7 +177,7 @@ func TestPipelineWalker(t *testing.T) {
// channel is closed // channel is closed
return return
} }
Assert(t, job != nil, "job is nil") rtest.Assert(t, job != nil, "job is nil")
switch j := job.(type) { switch j := job.(type) {
case pipe.Dir: case pipe.Dir:
@ -215,7 +215,7 @@ func TestPipelineWalker(t *testing.T) {
} }
resCh := make(chan pipe.Result, 1) 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 // wait for all workers to terminate
wg.Wait() wg.Wait()
@ -223,10 +223,10 @@ func TestPipelineWalker(t *testing.T) {
// wait for top-level blob // wait for top-level blob
<-resCh <-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) 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 { func createFile(filename, data string) error {
@ -247,7 +247,7 @@ func createFile(filename, data string) error {
func TestPipeWalkerError(t *testing.T) { func TestPipeWalkerError(t *testing.T) {
dir, err := ioutil.TempDir("", "restic-test-") dir, err := ioutil.TempDir("", "restic-test-")
OK(t, err) rtest.OK(t, err)
base := filepath.Base(dir) base := filepath.Base(dir)
@ -264,13 +264,13 @@ func TestPipeWalkerError(t *testing.T) {
{[]string{}, false}, {[]string{}, false},
} }
OK(t, os.Mkdir(filepath.Join(dir, "a"), 0755)) rtest.OK(t, os.Mkdir(filepath.Join(dir, "a"), 0755))
OK(t, os.Mkdir(filepath.Join(dir, "b"), 0755)) rtest.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, "c"), 0755))
OK(t, createFile(filepath.Join(dir, "a", "file_a"), "file a")) rtest.OK(t, createFile(filepath.Join(dir, "a", "file_a"), "file a"))
OK(t, createFile(filepath.Join(dir, "b", "file_b"), "file b")) rtest.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, "c", "file_c"), "file c"))
ranHook := false ranHook := false
testdir := filepath.Join(dir, "b") testdir := filepath.Join(dir, "b")
@ -286,7 +286,7 @@ func TestPipeWalkerError(t *testing.T) {
t.Logf("in hook, removing test file %v", testdir) t.Logf("in hook, removing test file %v", testdir)
ranHook = true ranHook = true
OK(t, os.RemoveAll(testdir)) rtest.OK(t, os.RemoveAll(testdir))
}) })
ctx, cancel := context.WithCancel(context.TODO()) ctx, cancel := context.WithCancel(context.TODO())
@ -327,12 +327,12 @@ func TestPipeWalkerError(t *testing.T) {
cancel() cancel()
Assert(t, ranHook, "hook did not run") rtest.Assert(t, ranHook, "hook did not run")
OK(t, os.RemoveAll(dir)) rtest.OK(t, os.RemoveAll(dir))
} }
func BenchmarkPipelineWalker(b *testing.B) { func BenchmarkPipelineWalker(b *testing.B) {
if TestWalkerPath == "" { if rtest.TestWalkerPath == "" {
b.Skipf("walkerpath not set, skipping BenchPipelineWalker") b.Skipf("walkerpath not set, skipping BenchPipelineWalker")
} }
@ -418,7 +418,7 @@ func BenchmarkPipelineWalker(b *testing.B) {
}() }()
resCh := make(chan pipe.Result, 1) 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 // wait for all workers to terminate
wg.Wait() wg.Wait()
@ -431,18 +431,18 @@ func BenchmarkPipelineWalker(b *testing.B) {
} }
func TestPipelineWalkerMultiple(t *testing.T) { func TestPipelineWalkerMultiple(t *testing.T) {
if TestWalkerPath == "" { if rtest.TestWalkerPath == "" {
t.Skipf("walkerpath not set, skipping TestPipelineWalker") t.Skipf("walkerpath not set, skipping TestPipelineWalker")
} }
ctx, cancel := context.WithCancel(context.TODO()) ctx, cancel := context.WithCancel(context.TODO())
defer cancel() defer cancel()
paths, err := filepath.Glob(filepath.Join(TestWalkerPath, "*")) paths, err := filepath.Glob(filepath.Join(rtest.TestWalkerPath, "*"))
OK(t, err) rtest.OK(t, err)
before, err := statPath(TestWalkerPath) before, err := statPath(rtest.TestWalkerPath)
OK(t, err) rtest.OK(t, err)
t.Logf("walking paths %v with %d dirs, %d files", paths, t.Logf("walking paths %v with %d dirs, %d files", paths,
before.dirs, before.files) before.dirs, before.files)
@ -459,7 +459,7 @@ func TestPipelineWalkerMultiple(t *testing.T) {
// channel is closed // channel is closed
return return
} }
Assert(t, job != nil, "job is nil") rtest.Assert(t, job != nil, "job is nil")
switch j := job.(type) { switch j := job.(type) {
case pipe.Dir: 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) 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 { func dirsInPath(path string) int {
@ -530,7 +530,7 @@ func TestPipeWalkerRoot(t *testing.T) {
} }
cwd, err := os.Getwd() cwd, err := os.Getwd()
OK(t, err) rtest.OK(t, err)
testPaths := []string{ testPaths := []string{
string(filepath.Separator), string(filepath.Separator),
@ -546,11 +546,11 @@ func TestPipeWalkerRoot(t *testing.T) {
func testPipeWalkerRootWithPath(path string, t *testing.T) { func testPipeWalkerRootWithPath(path string, t *testing.T) {
pattern := filepath.Join(path, "*") pattern := filepath.Join(path, "*")
rootPaths, err := filepath.Glob(pattern) rootPaths, err := filepath.Glob(pattern)
OK(t, err) rtest.OK(t, err)
for i, p := range rootPaths { for i, p := range rootPaths {
rootPaths[i], err = filepath.Rel(path, p) 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)) 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 { filter := func(p string, fi os.FileInfo) bool {
p, err := filepath.Rel(path, p) p, err := filepath.Rel(path, p)
OK(t, err) rtest.OK(t, err)
return dirsInPath(p) <= 1 return dirsInPath(p) <= 1
} }

View File

@ -6,7 +6,7 @@ import (
"github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/repository"
"github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/restic"
. "github.com/restic/restic/internal/test" rtest "github.com/restic/restic/internal/test"
) )
func TestIndexSerialize(t *testing.T) { func TestIndexSerialize(t *testing.T) {
@ -52,43 +52,43 @@ func TestIndexSerialize(t *testing.T) {
wr := bytes.NewBuffer(nil) wr := bytes.NewBuffer(nil)
err := idx.Encode(wr) err := idx.Encode(wr)
OK(t, err) rtest.OK(t, err)
idx2, err := repository.DecodeIndex(wr.Bytes()) idx2, err := repository.DecodeIndex(wr.Bytes())
OK(t, err) rtest.OK(t, err)
Assert(t, idx2 != nil, rtest.Assert(t, idx2 != nil,
"nil returned for decoded index") "nil returned for decoded index")
wr2 := bytes.NewBuffer(nil) wr2 := bytes.NewBuffer(nil)
err = idx2.Encode(wr2) err = idx2.Encode(wr2)
OK(t, err) rtest.OK(t, err)
for _, testBlob := range tests { for _, testBlob := range tests {
list, err := idx.Lookup(testBlob.id, testBlob.tpe) list, err := idx.Lookup(testBlob.id, testBlob.tpe)
OK(t, err) rtest.OK(t, err)
if len(list) != 1 { if len(list) != 1 {
t.Errorf("expected one result for blob %v, got %v: %v", testBlob.id.Str(), len(list), list) t.Errorf("expected one result for blob %v, got %v: %v", testBlob.id.Str(), len(list), list)
} }
result := list[0] result := list[0]
Equals(t, testBlob.pack, result.PackID) rtest.Equals(t, testBlob.pack, result.PackID)
Equals(t, testBlob.tpe, result.Type) rtest.Equals(t, testBlob.tpe, result.Type)
Equals(t, testBlob.offset, result.Offset) rtest.Equals(t, testBlob.offset, result.Offset)
Equals(t, testBlob.length, result.Length) rtest.Equals(t, testBlob.length, result.Length)
list2, err := idx2.Lookup(testBlob.id, testBlob.tpe) list2, err := idx2.Lookup(testBlob.id, testBlob.tpe)
OK(t, err) rtest.OK(t, err)
if len(list2) != 1 { if len(list2) != 1 {
t.Errorf("expected one result for blob %v, got %v: %v", testBlob.id.Str(), len(list2), list2) t.Errorf("expected one result for blob %v, got %v: %v", testBlob.id.Str(), len(list2), list2)
} }
result2 := list2[0] result2 := list2[0]
Equals(t, testBlob.pack, result2.PackID) rtest.Equals(t, testBlob.pack, result2.PackID)
Equals(t, testBlob.tpe, result2.Type) rtest.Equals(t, testBlob.tpe, result2.Type)
Equals(t, testBlob.offset, result2.Offset) rtest.Equals(t, testBlob.offset, result2.Offset)
Equals(t, testBlob.length, result2.Length) rtest.Equals(t, testBlob.length, result2.Length)
} }
// add more blobs to idx // add more blobs to idx
@ -125,28 +125,28 @@ func TestIndexSerialize(t *testing.T) {
// serialize idx, unserialize to idx3 // serialize idx, unserialize to idx3
wr3 := bytes.NewBuffer(nil) wr3 := bytes.NewBuffer(nil)
err = idx.Finalize(wr3) 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") "index not final after encoding")
id := restic.NewRandomID() id := restic.NewRandomID()
OK(t, idx.SetID(id)) rtest.OK(t, idx.SetID(id))
id2, err := idx.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) "wrong ID returned: want %v, got %v", id, id2)
idx3, err := repository.DecodeIndex(wr3.Bytes()) idx3, err := repository.DecodeIndex(wr3.Bytes())
OK(t, err) rtest.OK(t, err)
Assert(t, idx3 != nil, rtest.Assert(t, idx3 != nil,
"nil returned for decoded index") "nil returned for decoded index")
Assert(t, idx3.Final(), rtest.Assert(t, idx3.Final(),
"decoded index is not final") "decoded index is not final")
// all new blobs must be in the index // all new blobs must be in the index
for _, testBlob := range newtests { for _, testBlob := range newtests {
list, err := idx3.Lookup(testBlob.id, testBlob.tpe) list, err := idx3.Lookup(testBlob.id, testBlob.tpe)
OK(t, err) rtest.OK(t, err)
if len(list) != 1 { if len(list) != 1 {
t.Errorf("expected one result for blob %v, got %v: %v", testBlob.id.Str(), len(list), list) 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] blob := list[0]
Equals(t, testBlob.pack, blob.PackID) rtest.Equals(t, testBlob.pack, blob.PackID)
Equals(t, testBlob.tpe, blob.Type) rtest.Equals(t, testBlob.tpe, blob.Type)
Equals(t, testBlob.offset, blob.Offset) rtest.Equals(t, testBlob.offset, blob.Offset)
Equals(t, testBlob.length, blob.Length) rtest.Equals(t, testBlob.length, blob.Length)
} }
} }
@ -190,7 +190,7 @@ func TestIndexSize(t *testing.T) {
wr := bytes.NewBuffer(nil) wr := bytes.NewBuffer(nil)
err := idx.Encode(wr) 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()) 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")} oldIdx := restic.IDs{restic.TestParseID("ed54ae36197f4745ebc4b54d10e0f623eaaaedd03013eb7ae90df881b7781452")}
idx, err := repository.DecodeIndex(docExample) idx, err := repository.DecodeIndex(docExample)
OK(t, err) rtest.OK(t, err)
for _, test := range exampleTests { for _, test := range exampleTests {
list, err := idx.Lookup(test.id, test.tpe) list, err := idx.Lookup(test.id, test.tpe)
OK(t, err) rtest.OK(t, err)
if len(list) != 1 { if len(list) != 1 {
t.Errorf("expected one result for blob %v, got %v: %v", test.id.Str(), len(list), list) 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) t.Logf("looking for blob %v/%v, got %v", test.tpe, test.id.Str(), blob)
Equals(t, test.packID, blob.PackID) rtest.Equals(t, test.packID, blob.PackID)
Equals(t, test.tpe, blob.Type) rtest.Equals(t, test.tpe, blob.Type)
Equals(t, test.offset, blob.Offset) rtest.Equals(t, test.offset, blob.Offset)
Equals(t, test.length, blob.Length) rtest.Equals(t, test.length, blob.Length)
} }
Equals(t, oldIdx, idx.Supersedes()) rtest.Equals(t, oldIdx, idx.Supersedes())
blobs := idx.ListPack(exampleLookupTest.packID) blobs := idx.ListPack(exampleLookupTest.packID)
if len(blobs) != len(exampleLookupTest.blobs) { if len(blobs) != len(exampleLookupTest.blobs) {
@ -331,30 +331,30 @@ func BenchmarkDecodeIndex(b *testing.B) {
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
_, err := repository.DecodeIndex(docExample) _, err := repository.DecodeIndex(docExample)
OK(b, err) rtest.OK(b, err)
} }
} }
func TestIndexUnserializeOld(t *testing.T) { func TestIndexUnserializeOld(t *testing.T) {
idx, err := repository.DecodeOldIndex(docOldExample) idx, err := repository.DecodeOldIndex(docOldExample)
OK(t, err) rtest.OK(t, err)
for _, test := range exampleTests { for _, test := range exampleTests {
list, err := idx.Lookup(test.id, test.tpe) list, err := idx.Lookup(test.id, test.tpe)
OK(t, err) rtest.OK(t, err)
if len(list) != 1 { if len(list) != 1 {
t.Errorf("expected one result for blob %v, got %v: %v", test.id.Str(), len(list), list) t.Errorf("expected one result for blob %v, got %v: %v", test.id.Str(), len(list), list)
} }
blob := list[0] blob := list[0]
Equals(t, test.packID, blob.PackID) rtest.Equals(t, test.packID, blob.PackID)
Equals(t, test.tpe, blob.Type) rtest.Equals(t, test.tpe, blob.Type)
Equals(t, test.offset, blob.Offset) rtest.Equals(t, test.offset, blob.Offset)
Equals(t, test.length, blob.Length) 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) { func TestIndexPacks(t *testing.T) {
@ -377,5 +377,5 @@ func TestIndexPacks(t *testing.T) {
} }
idxPacks := idx.Packs() 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")
} }

View File

@ -10,7 +10,7 @@ import (
"github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/restic"
"github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/repository"
. "github.com/restic/restic/internal/test" rtest "github.com/restic/restic/internal/test"
) )
type testIDs []string type testIDs []string
@ -102,7 +102,7 @@ func TestFilesInParallel(t *testing.T) {
for n := uint(1); n < 5; n++ { for n := uint(1); n < 5; n++ {
err := repository.FilesInParallel(context.TODO(), lister, restic.DataFile, n*100, f) 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++ { for n := uint(1); n < 5; n++ {
err := repository.FilesInParallel(context.TODO(), lister, restic.DataFile, n*100, f) err := repository.FilesInParallel(context.TODO(), lister, restic.DataFile, n*100, f)
Equals(t, errTest, err) rtest.Equals(t, errTest, err)
} }
} }

View File

@ -13,7 +13,7 @@ import (
"github.com/restic/restic/internal/archiver" "github.com/restic/restic/internal/archiver"
"github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/repository"
"github.com/restic/restic/internal/restic" "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} var testSizes = []int{5, 23, 2<<18 + 23, 1 << 20}
@ -27,30 +27,30 @@ func TestSave(t *testing.T) {
for _, size := range testSizes { for _, size := range testSizes {
data := make([]byte, size) data := make([]byte, size)
_, err := io.ReadFull(rnd, data) _, err := io.ReadFull(rnd, data)
OK(t, err) rtest.OK(t, err)
id := restic.Hash(data) id := restic.Hash(data)
// save // save
sid, err := repo.SaveBlob(context.TODO(), restic.DataBlob, data, restic.ID{}) 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()) rtest.OK(t, repo.Flush())
// OK(t, repo.SaveIndex()) // rtest.OK(t, repo.SaveIndex())
// read back // read back
buf := restic.NewBlobBuffer(size) buf := restic.NewBlobBuffer(size)
n, err := repo.LoadBlob(context.TODO(), restic.DataBlob, id, buf) n, err := repo.LoadBlob(context.TODO(), restic.DataBlob, id, buf)
OK(t, err) rtest.OK(t, err)
Equals(t, len(buf), n) 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", "number of bytes read back does not match: expected %d, got %d",
len(data), len(buf)) 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 does not match: expected %02x, got %02x",
data, buf) data, buf)
} }
@ -63,28 +63,28 @@ func TestSaveFrom(t *testing.T) {
for _, size := range testSizes { for _, size := range testSizes {
data := make([]byte, size) data := make([]byte, size)
_, err := io.ReadFull(rnd, data) _, err := io.ReadFull(rnd, data)
OK(t, err) rtest.OK(t, err)
id := restic.Hash(data) id := restic.Hash(data)
// save // save
id2, err := repo.SaveBlob(context.TODO(), restic.DataBlob, data, id) id2, err := repo.SaveBlob(context.TODO(), restic.DataBlob, data, id)
OK(t, err) rtest.OK(t, err)
Equals(t, id, id2) rtest.Equals(t, id, id2)
OK(t, repo.Flush()) rtest.OK(t, repo.Flush())
// read back // read back
buf := restic.NewBlobBuffer(size) buf := restic.NewBlobBuffer(size)
n, err := repo.LoadBlob(context.TODO(), restic.DataBlob, id, buf) n, err := repo.LoadBlob(context.TODO(), restic.DataBlob, id, buf)
OK(t, err) rtest.OK(t, err)
Equals(t, len(buf), n) 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", "number of bytes read back does not match: expected %d, got %d",
len(data), len(buf)) 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 does not match: expected %02x, got %02x",
data, buf) data, buf)
} }
@ -98,7 +98,7 @@ func BenchmarkSaveAndEncrypt(t *testing.B) {
data := make([]byte, size) data := make([]byte, size)
_, err := io.ReadFull(rnd, data) _, err := io.ReadFull(rnd, data)
OK(t, err) rtest.OK(t, err)
id := restic.ID(sha256.Sum256(data)) id := restic.ID(sha256.Sum256(data))
@ -108,7 +108,7 @@ func BenchmarkSaveAndEncrypt(t *testing.B) {
for i := 0; i < t.N; i++ { for i := 0; i < t.N; i++ {
// save // save
_, err = repo.SaveBlob(context.TODO(), restic.DataBlob, data, id) _, 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) repo, cleanup := repository.TestRepository(t)
defer cleanup() defer cleanup()
if BenchArchiveDirectory == "" { if rtest.BenchArchiveDirectory == "" {
t.Skip("benchdir not set, skipping") t.Skip("benchdir not set, skipping")
} }
// archive a few files // archive a few files
sn := archiver.TestSnapshot(t, repo, BenchArchiveDirectory, nil) sn := archiver.TestSnapshot(t, repo, rtest.BenchArchiveDirectory, nil)
OK(t, repo.Flush()) rtest.OK(t, repo.Flush())
_, err := repo.LoadTree(context.TODO(), *sn.Tree) _, err := repo.LoadTree(context.TODO(), *sn.Tree)
OK(t, err) rtest.OK(t, err)
} }
func BenchmarkLoadTree(t *testing.B) { func BenchmarkLoadTree(t *testing.B) {
repo, cleanup := repository.TestRepository(t) repo, cleanup := repository.TestRepository(t)
defer cleanup() defer cleanup()
if BenchArchiveDirectory == "" { if rtest.BenchArchiveDirectory == "" {
t.Skip("benchdir not set, skipping") t.Skip("benchdir not set, skipping")
} }
// archive a few files // archive a few files
sn := archiver.TestSnapshot(t, repo, BenchArchiveDirectory, nil) sn := archiver.TestSnapshot(t, repo, rtest.BenchArchiveDirectory, nil)
OK(t, repo.Flush()) rtest.OK(t, repo.Flush())
t.ResetTimer() t.ResetTimer()
for i := 0; i < t.N; i++ { for i := 0; i < t.N; i++ {
_, err := repo.LoadTree(context.TODO(), *sn.Tree) _, 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 length := 1000000
buf := restic.NewBlobBuffer(length) buf := restic.NewBlobBuffer(length)
_, err := io.ReadFull(rnd, buf) _, err := io.ReadFull(rnd, buf)
OK(t, err) rtest.OK(t, err)
id, err := repo.SaveBlob(context.TODO(), restic.DataBlob, buf, restic.ID{}) id, err := repo.SaveBlob(context.TODO(), restic.DataBlob, buf, restic.ID{})
OK(t, err) rtest.OK(t, err)
OK(t, repo.Flush()) rtest.OK(t, repo.Flush())
// first, test with buffers that are too small // first, test with buffers that are too small
for _, testlength := range []int{length - 20, length, restic.CiphertextLength(length) - 1} { for _, testlength := range []int{length - 20, length, restic.CiphertextLength(length) - 1} {
@ -200,18 +200,18 @@ func BenchmarkLoadBlob(b *testing.B) {
length := 1000000 length := 1000000
buf := restic.NewBlobBuffer(length) buf := restic.NewBlobBuffer(length)
_, err := io.ReadFull(rnd, buf) _, err := io.ReadFull(rnd, buf)
OK(b, err) rtest.OK(b, err)
id, err := repo.SaveBlob(context.TODO(), restic.DataBlob, buf, restic.ID{}) id, err := repo.SaveBlob(context.TODO(), restic.DataBlob, buf, restic.ID{})
OK(b, err) rtest.OK(b, err)
OK(b, repo.Flush()) rtest.OK(b, repo.Flush())
b.ResetTimer() b.ResetTimer()
b.SetBytes(int64(length)) b.SetBytes(int64(length))
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
n, err := repo.LoadBlob(context.TODO(), restic.DataBlob, id, buf) n, err := repo.LoadBlob(context.TODO(), restic.DataBlob, id, buf)
OK(b, err) rtest.OK(b, err)
if n != length { if n != length {
b.Errorf("wanted %d bytes, got %d", length, n) b.Errorf("wanted %d bytes, got %d", length, n)
} }
@ -230,20 +230,20 @@ func BenchmarkLoadAndDecrypt(b *testing.B) {
length := 1000000 length := 1000000
buf := restic.NewBlobBuffer(length) buf := restic.NewBlobBuffer(length)
_, err := io.ReadFull(rnd, buf) _, err := io.ReadFull(rnd, buf)
OK(b, err) rtest.OK(b, err)
dataID := restic.Hash(buf) dataID := restic.Hash(buf)
storageID, err := repo.SaveUnpacked(context.TODO(), restic.DataFile, buf) storageID, err := repo.SaveUnpacked(context.TODO(), restic.DataFile, buf)
OK(b, err) rtest.OK(b, err)
// OK(b, repo.Flush()) // rtest.OK(b, repo.Flush())
b.ResetTimer() b.ResetTimer()
b.SetBytes(int64(length)) b.SetBytes(int64(length))
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
data, err := repo.LoadAndDecrypt(context.TODO(), restic.DataFile, storageID) data, err := repo.LoadAndDecrypt(context.TODO(), restic.DataFile, storageID)
OK(b, err) rtest.OK(b, err)
if len(data) != length { if len(data) != length {
b.Errorf("wanted %d bytes, got %d", length, len(data)) b.Errorf("wanted %d bytes, got %d", length, len(data))
} }
@ -259,7 +259,7 @@ func TestLoadJSONUnpacked(t *testing.T) {
repo, cleanup := repository.TestRepository(t) repo, cleanup := repository.TestRepository(t)
defer cleanup() defer cleanup()
if BenchArchiveDirectory == "" { if rtest.BenchArchiveDirectory == "" {
t.Skip("benchdir not set, skipping") t.Skip("benchdir not set, skipping")
} }
@ -269,26 +269,26 @@ func TestLoadJSONUnpacked(t *testing.T) {
sn.Username = "test!" sn.Username = "test!"
id, err := repo.SaveJSONUnpacked(context.TODO(), restic.SnapshotFile, &sn) id, err := repo.SaveJSONUnpacked(context.TODO(), restic.SnapshotFile, &sn)
OK(t, err) rtest.OK(t, err)
var sn2 restic.Snapshot var sn2 restic.Snapshot
// restore // restore
err = repo.LoadJSONUnpacked(context.TODO(), restic.SnapshotFile, id, &sn2) err = repo.LoadJSONUnpacked(context.TODO(), restic.SnapshotFile, id, &sn2)
OK(t, err) rtest.OK(t, err)
Equals(t, sn.Hostname, sn2.Hostname) rtest.Equals(t, sn.Hostname, sn2.Hostname)
Equals(t, sn.Username, sn2.Username) rtest.Equals(t, sn.Username, sn2.Username)
} }
var repoFixture = filepath.Join("testdata", "test-repo.tar.gz") var repoFixture = filepath.Join("testdata", "test-repo.tar.gz")
func TestRepositoryLoadIndex(t *testing.T) { func TestRepositoryLoadIndex(t *testing.T) {
repodir, cleanup := Env(t, repoFixture) repodir, cleanup := rtest.Env(t, repoFixture)
defer cleanup() defer cleanup()
repo := repository.TestOpenLocal(t, repodir) repo := repository.TestOpenLocal(t, repodir)
OK(t, repo.LoadIndex(context.TODO())) rtest.OK(t, repo.LoadIndex(context.TODO()))
} }
func BenchmarkLoadIndex(b *testing.B) { func BenchmarkLoadIndex(b *testing.B) {
@ -312,18 +312,18 @@ func BenchmarkLoadIndex(b *testing.B) {
} }
id, err := repository.SaveIndex(context.TODO(), repo, idx) 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)) 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()}) 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.Logf("filesize is %v", fi.Size)
b.ResetTimer() b.ResetTimer()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
_, err := repository.LoadIndex(context.TODO(), repo, id) _, 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) buf := make([]byte, size)
_, err := io.ReadFull(rnd, buf) _, err := io.ReadFull(rnd, buf)
OK(t, err) rtest.OK(t, err)
_, err = repo.SaveBlob(context.TODO(), restic.DataBlob, buf, restic.ID{}) _, 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 // add 3 packs, write intermediate index
for i := 0; i < 3; i++ { for i := 0; i < 3; i++ {
saveRandomDataBlobs(t, repo, 5, 1<<15) 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 // add another 5 packs
for i := 0; i < 5; i++ { for i := 0; i < 5; i++ {
saveRandomDataBlobs(t, repo, 5, 1<<15) saveRandomDataBlobs(t, repo, 5, 1<<15)
OK(t, repo.Flush()) rtest.OK(t, repo.Flush())
} }
// save final index // 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{}) packEntries := make(map[restic.ID]map[restic.ID]struct{})
for id := range repo.List(context.TODO(), restic.IndexFile) { for id := range repo.List(context.TODO(), restic.IndexFile) {
idx, err := repository.LoadIndex(context.TODO(), repo, id) idx, err := repository.LoadIndex(context.TODO(), repo, id)
OK(t, err) rtest.OK(t, err)
for pb := range idx.Each(context.TODO()) { for pb := range idx.Each(context.TODO()) {
if _, ok := packEntries[pb.PackID]; !ok { if _, ok := packEntries[pb.PackID]; !ok {

View File

@ -5,7 +5,7 @@ import (
"testing" "testing"
"github.com/restic/restic/internal/restic" "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) 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) { func TestConfig(t *testing.T) {
resultConfig := restic.Config{} resultConfig := restic.Config{}
save := func(tpe restic.FileType, arg interface{}) (restic.ID, error) { 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", "wrong backend type: got %v, wanted %v",
tpe, restic.ConfigFile) tpe, restic.ConfigFile)
@ -33,12 +33,12 @@ func TestConfig(t *testing.T) {
} }
cfg1, err := restic.CreateConfig() cfg1, err := restic.CreateConfig()
OK(t, err) rtest.OK(t, err)
_, err = saver(save).SaveJSONUnpacked(restic.ConfigFile, cfg1) _, err = saver(save).SaveJSONUnpacked(restic.ConfigFile, cfg1)
load := func(ctx context.Context, tpe restic.FileType, id restic.ID, arg interface{}) error { 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", "wrong backend type: got %v, wanted %v",
tpe, restic.ConfigFile) tpe, restic.ConfigFile)
@ -48,8 +48,8 @@ func TestConfig(t *testing.T) {
} }
cfg2, err := restic.LoadConfig(context.TODO(), loader(load)) 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) "configs aren't equal: %v != %v", cfg1, cfg2)
} }

View File

@ -4,7 +4,7 @@ import (
"testing" "testing"
"github.com/restic/restic/internal/restic" "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. // TestHardLinks contains various tests for HardlinkIndex.
@ -17,19 +17,19 @@ func TestHardLinks(t *testing.T) {
var sresult string var sresult string
sresult = idx.GetFilename(1, 2) 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) sresult = idx.GetFilename(2, 3)
Equals(t, sresult, "inode2-file2-on-device3") rtest.Equals(t, sresult, "inode2-file2-on-device3")
var bresult bool var bresult bool
bresult = idx.Has(1, 2) bresult = idx.Has(1, 2)
Equals(t, bresult, true) rtest.Equals(t, bresult, true)
bresult = idx.Has(1, 3) bresult = idx.Has(1, 3)
Equals(t, bresult, false) rtest.Equals(t, bresult, false)
idx.Remove(1, 2) idx.Remove(1, 2)
bresult = idx.Has(1, 2) bresult = idx.Has(1, 2)
Equals(t, bresult, false) rtest.Equals(t, bresult, false)
} }

View File

@ -8,7 +8,7 @@ import (
"github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/repository"
"github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/restic"
. "github.com/restic/restic/internal/test" rtest "github.com/restic/restic/internal/test"
) )
func TestLock(t *testing.T) { func TestLock(t *testing.T) {
@ -16,9 +16,9 @@ func TestLock(t *testing.T) {
defer cleanup() defer cleanup()
lock, err := restic.NewLock(context.TODO(), repo) 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) { func TestDoubleUnlock(t *testing.T) {
@ -26,12 +26,12 @@ func TestDoubleUnlock(t *testing.T) {
defer cleanup() defer cleanup()
lock, err := restic.NewLock(context.TODO(), repo) 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() err = lock.Unlock()
Assert(t, err != nil, rtest.Assert(t, err != nil,
"double unlock didn't return an error, got %v", err) "double unlock didn't return an error, got %v", err)
} }
@ -40,13 +40,13 @@ func TestMultipleLock(t *testing.T) {
defer cleanup() defer cleanup()
lock1, err := restic.NewLock(context.TODO(), repo) lock1, err := restic.NewLock(context.TODO(), repo)
OK(t, err) rtest.OK(t, err)
lock2, err := restic.NewLock(context.TODO(), repo) lock2, err := restic.NewLock(context.TODO(), repo)
OK(t, err) rtest.OK(t, err)
OK(t, lock1.Unlock()) rtest.OK(t, lock1.Unlock())
OK(t, lock2.Unlock()) rtest.OK(t, lock2.Unlock())
} }
func TestLockExclusive(t *testing.T) { func TestLockExclusive(t *testing.T) {
@ -54,8 +54,8 @@ func TestLockExclusive(t *testing.T) {
defer cleanup() defer cleanup()
elock, err := restic.NewExclusiveLock(context.TODO(), repo) elock, err := restic.NewExclusiveLock(context.TODO(), repo)
OK(t, err) rtest.OK(t, err)
OK(t, elock.Unlock()) rtest.OK(t, elock.Unlock())
} }
func TestLockOnExclusiveLockedRepo(t *testing.T) { func TestLockOnExclusiveLockedRepo(t *testing.T) {
@ -63,16 +63,16 @@ func TestLockOnExclusiveLockedRepo(t *testing.T) {
defer cleanup() defer cleanup()
elock, err := restic.NewExclusiveLock(context.TODO(), repo) elock, err := restic.NewExclusiveLock(context.TODO(), repo)
OK(t, err) rtest.OK(t, err)
lock, err := restic.NewLock(context.TODO(), repo) 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") "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") "create normal lock with exclusively locked repo didn't return the correct error")
OK(t, lock.Unlock()) rtest.OK(t, lock.Unlock())
OK(t, elock.Unlock()) rtest.OK(t, elock.Unlock())
} }
func TestExclusiveLockOnLockedRepo(t *testing.T) { func TestExclusiveLockOnLockedRepo(t *testing.T) {
@ -80,16 +80,16 @@ func TestExclusiveLockOnLockedRepo(t *testing.T) {
defer cleanup() defer cleanup()
elock, err := restic.NewLock(context.TODO(), repo) elock, err := restic.NewLock(context.TODO(), repo)
OK(t, err) rtest.OK(t, err)
lock, err := restic.NewExclusiveLock(context.TODO(), repo) 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") "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") "create normal lock with exclusively locked repo didn't return the correct error")
OK(t, lock.Unlock()) rtest.OK(t, lock.Unlock())
OK(t, elock.Unlock()) rtest.OK(t, elock.Unlock())
} }
func createFakeLock(repo restic.Repository, t time.Time, pid int) (restic.ID, error) { 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) { func TestLockStale(t *testing.T) {
hostname, err := os.Hostname() hostname, err := os.Hostname()
OK(t, err) rtest.OK(t, err)
otherHostname := "other-" + hostname otherHostname := "other-" + hostname
@ -152,12 +152,12 @@ func TestLockStale(t *testing.T) {
Hostname: hostname, Hostname: hostname,
} }
Assert(t, lock.Stale() == test.stale, rtest.Assert(t, lock.Stale() == test.stale,
"TestStaleLock: test %d failed: expected stale: %v, got %v", "TestStaleLock: test %d failed: expected stale: %v, got %v",
i, test.stale, !test.stale) i, test.stale, !test.stale)
lock.Hostname = otherHostname 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", "TestStaleLock: test %d failed: expected staleOnOtherHost: %v, got %v",
i, test.staleOnOtherHost, !test.staleOnOtherHost) 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 { func lockExists(repo restic.Repository, t testing.TB, id restic.ID) bool {
h := restic.Handle{Type: restic.LockFile, Name: id.String()} h := restic.Handle{Type: restic.LockFile, Name: id.String()}
exists, err := repo.Backend().Test(context.TODO(), h) exists, err := repo.Backend().Test(context.TODO(), h)
OK(t, err) rtest.OK(t, err)
return exists return exists
} }
@ -176,24 +176,24 @@ func TestLockWithStaleLock(t *testing.T) {
defer cleanup() defer cleanup()
id1, err := createFakeLock(repo, time.Now().Add(-time.Hour), os.Getpid()) 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()) 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) 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") "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") "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") "stale lock still exists after RemoveStaleLocks was called")
OK(t, removeLock(repo, id2)) rtest.OK(t, removeLock(repo, id2))
} }
func TestRemoveAllLocks(t *testing.T) { func TestRemoveAllLocks(t *testing.T) {
@ -201,21 +201,21 @@ func TestRemoveAllLocks(t *testing.T) {
defer cleanup() defer cleanup()
id1, err := createFakeLock(repo, time.Now().Add(-time.Hour), os.Getpid()) 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()) 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) 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") "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") "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") "lock still exists after RemoveAllLocks was called")
} }
@ -224,7 +224,7 @@ func TestLockRefresh(t *testing.T) {
defer cleanup() defer cleanup()
lock, err := restic.NewLock(context.TODO(), repo) lock, err := restic.NewLock(context.TODO(), repo)
OK(t, err) rtest.OK(t, err)
var lockID *restic.ID var lockID *restic.ID
for id := range repo.List(context.TODO(), restic.LockFile) { for id := range repo.List(context.TODO(), restic.LockFile) {
@ -234,7 +234,7 @@ func TestLockRefresh(t *testing.T) {
lockID = &id lockID = &id
} }
OK(t, lock.Refresh(context.TODO())) rtest.OK(t, lock.Refresh(context.TODO()))
var lockID2 *restic.ID var lockID2 *restic.ID
for id := range repo.List(context.TODO(), restic.LockFile) { for id := range repo.List(context.TODO(), restic.LockFile) {
@ -244,7 +244,7 @@ func TestLockRefresh(t *testing.T) {
lockID2 = &id lockID2 = &id
} }
Assert(t, !lockID.Equal(*lockID2), rtest.Assert(t, !lockID.Equal(*lockID2),
"expected a new ID after lock refresh, got the same") "expected a new ID after lock refresh, got the same")
OK(t, lock.Unlock()) rtest.OK(t, lock.Unlock())
} }

View File

@ -10,7 +10,7 @@ import (
"time" "time"
"github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/restic"
. "github.com/restic/restic/internal/test" rtest "github.com/restic/restic/internal/test"
) )
func BenchmarkNodeFillUser(t *testing.B) { func BenchmarkNodeFillUser(t *testing.B) {
@ -32,8 +32,8 @@ func BenchmarkNodeFillUser(t *testing.B) {
restic.NodeFromFileInfo(path, fi) restic.NodeFromFileInfo(path, fi)
} }
OK(t, tempfile.Close()) rtest.OK(t, tempfile.Close())
RemoveAll(t, tempfile.Name()) rtest.RemoveAll(t, tempfile.Name())
} }
func BenchmarkNodeFromFileInfo(t *testing.B) { func BenchmarkNodeFromFileInfo(t *testing.B) {
@ -58,8 +58,8 @@ func BenchmarkNodeFromFileInfo(t *testing.B) {
} }
} }
OK(t, tempfile.Close()) rtest.OK(t, tempfile.Close())
RemoveAll(t, tempfile.Name()) rtest.RemoveAll(t, tempfile.Name())
} }
func parseTime(s string) time.Time { func parseTime(s string) time.Time {
@ -166,12 +166,12 @@ var nodeTests = []restic.Node{
} }
func TestNodeRestoreAt(t *testing.T) { func TestNodeRestoreAt(t *testing.T) {
tempdir, err := ioutil.TempDir(TestTempDir, "restic-test-") tempdir, err := ioutil.TempDir(rtest.TestTempDir, "restic-test-")
OK(t, err) rtest.OK(t, err)
defer func() { defer func() {
if TestCleanupTempDirs { if rtest.TestCleanupTempDirs {
RemoveAll(t, tempdir) rtest.RemoveAll(t, tempdir)
} else { } else {
t.Logf("leaving tempdir at %v", tempdir) t.Logf("leaving tempdir at %v", tempdir)
} }
@ -181,35 +181,35 @@ func TestNodeRestoreAt(t *testing.T) {
for _, test := range nodeTests { for _, test := range nodeTests {
nodePath := filepath.Join(tempdir, test.Name) 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" { if test.Type == "symlink" && runtime.GOOS == "windows" {
continue continue
} }
if test.Type == "dir" { if test.Type == "dir" {
OK(t, test.RestoreTimestamps(nodePath)) rtest.OK(t, test.RestoreTimestamps(nodePath))
} }
fi, err := os.Lstat(nodePath) fi, err := os.Lstat(nodePath)
OK(t, err) rtest.OK(t, err)
n2, err := restic.NodeFromFileInfo(nodePath, fi) 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) "%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) "%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) "%v: size doesn't match (%v != %v)", test.Size, test.Size, n2.Size)
if runtime.GOOS != "windows" { 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) "%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) "%v: GID doesn't match (%v != %v)", test.Type, test.GID, n2.GID)
if test.Type != "symlink" { 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) "%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) 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)
} }

View File

@ -5,12 +5,12 @@ import (
"time" "time"
"github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/restic"
. "github.com/restic/restic/internal/test" rtest "github.com/restic/restic/internal/test"
) )
func TestNewSnapshot(t *testing.T) { func TestNewSnapshot(t *testing.T) {
paths := []string{"/home/foobar"} paths := []string{"/home/foobar"}
_, err := restic.NewSnapshot(paths, nil, "foo", time.Now()) _, err := restic.NewSnapshot(paths, nil, "foo", time.Now())
OK(t, err) rtest.OK(t, err)
} }

View File

@ -10,7 +10,7 @@ import (
"github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/repository"
"github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/restic"
. "github.com/restic/restic/internal/test" rtest "github.com/restic/restic/internal/test"
) )
var testFiles = []struct { var testFiles = []struct {
@ -23,25 +23,25 @@ var testFiles = []struct {
} }
func createTempDir(t *testing.T) string { func createTempDir(t *testing.T) string {
tempdir, err := ioutil.TempDir(TestTempDir, "restic-test-") tempdir, err := ioutil.TempDir(rtest.TestTempDir, "restic-test-")
OK(t, err) rtest.OK(t, err)
for _, test := range testFiles { for _, test := range testFiles {
file := filepath.Join(tempdir, test.name) file := filepath.Join(tempdir, test.name)
dir := filepath.Dir(file) dir := filepath.Dir(file)
if dir != "." { if dir != "." {
OK(t, os.MkdirAll(dir, 0755)) rtest.OK(t, os.MkdirAll(dir, 0755))
} }
f, err := os.Create(file) f, err := os.Create(file)
defer func() { defer func() {
OK(t, f.Close()) rtest.OK(t, f.Close())
}() }()
OK(t, err) rtest.OK(t, err)
_, err = f.Write(test.content) _, err = f.Write(test.content)
OK(t, err) rtest.OK(t, err)
} }
return tempdir return tempdir
@ -50,8 +50,8 @@ func createTempDir(t *testing.T) string {
func TestTree(t *testing.T) { func TestTree(t *testing.T) {
dir := createTempDir(t) dir := createTempDir(t)
defer func() { defer func() {
if TestCleanupTempDirs { if rtest.TestCleanupTempDirs {
RemoveAll(t, dir) rtest.RemoveAll(t, dir)
} }
}() }()
} }
@ -67,11 +67,11 @@ var testNodes = []restic.Node{
func TestNodeMarshal(t *testing.T) { func TestNodeMarshal(t *testing.T) {
for i, n := range testNodes { for i, n := range testNodes {
data, err := json.Marshal(&n) data, err := json.Marshal(&n)
OK(t, err) rtest.OK(t, err)
var node restic.Node var node restic.Node
err = json.Unmarshal(data, &node) err = json.Unmarshal(data, &node)
OK(t, err) rtest.OK(t, err)
if n.Name != node.Name { if n.Name != node.Name {
t.Fatalf("Node %d: Names are not equal, want: %q got: %q", i, 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) { func TestNodeComparison(t *testing.T) {
fi, err := os.Lstat("tree_test.go") fi, err := os.Lstat("tree_test.go")
OK(t, err) rtest.OK(t, err)
node, err := restic.NodeFromFileInfo("tree_test.go", fi) node, err := restic.NodeFromFileInfo("tree_test.go", fi)
OK(t, err) rtest.OK(t, err)
n2 := *node n2 := *node
Assert(t, node.Equals(n2), "nodes aren't equal") rtest.Assert(t, node.Equals(n2), "nodes aren't equal")
n2.Size-- n2.Size--
Assert(t, !node.Equals(n2), "nodes are equal") rtest.Assert(t, !node.Equals(n2), "nodes are equal")
} }
func TestLoadTree(t *testing.T) { func TestLoadTree(t *testing.T) {
@ -100,16 +100,16 @@ func TestLoadTree(t *testing.T) {
// save tree // save tree
tree := restic.NewTree() tree := restic.NewTree()
id, err := repo.SaveTree(context.TODO(), tree) id, err := repo.SaveTree(context.TODO(), tree)
OK(t, err) rtest.OK(t, err)
// save packs // save packs
OK(t, repo.Flush()) rtest.OK(t, repo.Flush())
// load tree again // load tree again
tree2, err := repo.LoadTree(context.TODO(), id) 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", "trees are not equal: want %v, got %v",
tree, tree2) tree, tree2)
} }

View File

@ -12,7 +12,7 @@ import (
"github.com/restic/restic/internal/pipe" "github.com/restic/restic/internal/pipe"
"github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/repository"
"github.com/restic/restic/internal/restic" "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" "github.com/restic/restic/internal/walk"
) )
@ -20,16 +20,16 @@ func TestWalkTree(t *testing.T) {
repo, cleanup := repository.TestRepository(t) repo, cleanup := repository.TestRepository(t)
defer cleanup() defer cleanup()
dirs, err := filepath.Glob(TestWalkerPath) dirs, err := filepath.Glob(rtest.TestWalkerPath)
OK(t, err) rtest.OK(t, err)
// archive a few files // archive a few files
arch := archiver.New(repo) arch := archiver.New(repo)
sn, _, err := arch.Snapshot(context.TODO(), nil, dirs, nil, "localhost", nil, time.Now()) 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 // flush repo, write all packs
OK(t, repo.Flush()) rtest.OK(t, repo.Flush())
// start tree walker // start tree walker
treeJobs := make(chan walk.TreeJob) treeJobs := make(chan walk.TreeJob)
@ -47,10 +47,10 @@ func TestWalkTree(t *testing.T) {
for { for {
// receive fs job // receive fs job
fsJob, fsChOpen := <-fsJobs fsJob, fsChOpen := <-fsJobs
Assert(t, !fsChOpen || fsJob != nil, rtest.Assert(t, !fsChOpen || fsJob != nil,
"received nil job from filesystem: %v %v", fsJob, fsChOpen) "received nil job from filesystem: %v %v", fsJob, fsChOpen)
if fsJob != nil { if fsJob != nil {
OK(t, fsJob.Error()) rtest.OK(t, fsJob.Error())
} }
var path string var path string
@ -67,13 +67,13 @@ func TestWalkTree(t *testing.T) {
treeJob, treeChOpen := <-treeJobs treeJob, treeChOpen := <-treeJobs
treeEntries := 1 treeEntries := 1
OK(t, treeJob.Error) rtest.OK(t, treeJob.Error)
if treeJob.Tree != nil { if treeJob.Tree != nil {
treeEntries = len(treeJob.Tree.Nodes) treeEntries = len(treeJob.Tree.Nodes)
} }
Assert(t, fsChOpen == treeChOpen, rtest.Assert(t, fsChOpen == treeChOpen,
"one channel closed too early: fsChOpen %v, treeChOpen %v", "one channel closed too early: fsChOpen %v, treeChOpen %v",
fsChOpen, treeChOpen) fsChOpen, treeChOpen)
@ -81,10 +81,10 @@ func TestWalkTree(t *testing.T) {
break 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)) "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) "wrong number of entries: %v != %v", fsEntries, treeEntries)
} }
} }
@ -1340,14 +1340,14 @@ var walktreeTestItems = []string{
} }
func TestDelayedWalkTree(t *testing.T) { func TestDelayedWalkTree(t *testing.T) {
repodir, cleanup := Env(t, repoFixture) repodir, cleanup := rtest.Env(t, repoFixture)
defer cleanup() defer cleanup()
repo := repository.TestOpenLocal(t, repodir) repo := repository.TestOpenLocal(t, repodir)
OK(t, repo.LoadIndex(context.TODO())) rtest.OK(t, repo.LoadIndex(context.TODO()))
root, err := restic.ParseID("937a2f64f736c64ee700c6ab06f840c68c94799c288146a0e81e07f4c94254da") root, err := restic.ParseID("937a2f64f736c64ee700c6ab06f840c68c94799c288146a0e81e07f4c94254da")
OK(t, err) rtest.OK(t, err)
dr := delayRepo{repo, 100 * time.Millisecond} dr := delayRepo{repo, 100 * time.Millisecond}
@ -1370,14 +1370,14 @@ func TestDelayedWalkTree(t *testing.T) {
} }
func BenchmarkDelayedWalkTree(t *testing.B) { func BenchmarkDelayedWalkTree(t *testing.B) {
repodir, cleanup := Env(t, repoFixture) repodir, cleanup := rtest.Env(t, repoFixture)
defer cleanup() defer cleanup()
repo := repository.TestOpenLocal(t, repodir) repo := repository.TestOpenLocal(t, repodir)
OK(t, repo.LoadIndex(context.TODO())) rtest.OK(t, repo.LoadIndex(context.TODO()))
root, err := restic.ParseID("937a2f64f736c64ee700c6ab06f840c68c94799c288146a0e81e07f4c94254da") root, err := restic.ParseID("937a2f64f736c64ee700c6ab06f840c68c94799c288146a0e81e07f4c94254da")
OK(t, err) rtest.OK(t, err)
dr := delayRepo{repo, 10 * time.Millisecond} dr := delayRepo{repo, 10 * time.Millisecond}