Use rtest on these as well to keep codebase consistent

This commit is contained in:
Herbert 2017-10-02 17:48:08 +02:00
parent 3473c3f7b6
commit 033589a66b
3 changed files with 181 additions and 181 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" rtest "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{}
test.OK(t, runMount(opts, gopts, []string{dir})) rtest.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"))
test.OK(t, err) rtest.OK(t, err)
names, err := snapshotsDir.Readdirnames(-1) names, err := snapshotsDir.Readdirnames(-1)
test.OK(t, err) rtest.OK(t, err)
test.OK(t, snapshotsDir.Close()) rtest.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)
test.Assert(t, rtest.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)
test.OK(t, err) rtest.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 {
test.Assert(t, present, "Directory %s is present in fuse dir but is not a snapshot", name) rtest.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 !test.RunFuseTest { if !rtest.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)
test.OK(t, err) rtest.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
test.RemoveAll(t, env.mountpoint) rtest.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)
test.SetupTarTestFixture(t, env.testdata, filepath.Join("testdata", "backup-data.tar.gz")) rtest.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)
test.Assert(t, len(snapshotIDs) == 1, rtest.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)
test.Assert(t, len(snapshotIDs) == 2, rtest.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)
test.Assert(t, len(snapshotIDs) == 3, rtest.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 !test.RunFuseTest { if !rtest.RunFuseTest {
t.Skip("Skipping fuse tests") t.Skip("Skipping fuse tests")
} }
env, cleanup := withTestEnvironment(t) env, cleanup := withTestEnvironment(t)
defer cleanup() defer cleanup()
test.SetupTarTestFixture(t, env.base, filepath.Join("testdata", "repo-same-timestamps.tar.gz")) rtest.SetupTarTestFixture(t, env.base, filepath.Join("testdata", "repo-same-timestamps.tar.gz"))
repo, err := OpenRepository(env.gopts) repo, err := OpenRepository(env.gopts)
test.OK(t, err) rtest.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" rtest "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 !test.RunIntegrationTest { if !rtest.RunIntegrationTest {
t.Skip("integration tests disabled") t.Skip("integration tests disabled")
} }
repository.TestUseLowSecurityKDFParameters(t) repository.TestUseLowSecurityKDFParameters(t)
tempdir, err := ioutil.TempDir(test.TestTempDir, "restic-test-") tempdir, err := ioutil.TempDir(rtest.TestTempDir, "restic-test-")
test.OK(t, err) rtest.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"),
} }
test.OK(t, os.MkdirAll(env.mountpoint, 0700)) rtest.OK(t, os.MkdirAll(env.mountpoint, 0700))
test.OK(t, os.MkdirAll(env.testdata, 0700)) rtest.OK(t, os.MkdirAll(env.testdata, 0700))
test.OK(t, os.MkdirAll(env.cache, 0700)) rtest.OK(t, os.MkdirAll(env.cache, 0700))
test.OK(t, os.MkdirAll(env.repo, 0700)) rtest.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: test.TestPassword, password: rtest.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 !test.TestCleanupTempDirs { if !rtest.TestCleanupTempDirs {
t.Logf("leaving temporary directory %v used for test", tempdir) t.Logf("leaving temporary directory %v used for test", tempdir)
return return
} }
test.RemoveAll(t, tempdir) rtest.RemoveAll(t, tempdir)
} }
return env, cleanup return env, cleanup

View file

@ -22,7 +22,7 @@ import (
"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/restic" "github.com/restic/restic/internal/restic"
"github.com/restic/restic/internal/test" rtest "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 {
@ -46,13 +46,13 @@ func testRunInit(t testing.TB, opts GlobalOptions) {
repository.TestUseLowSecurityKDFParameters(t) repository.TestUseLowSecurityKDFParameters(t)
restic.TestSetLockTimeout(t, 0) restic.TestSetLockTimeout(t, 0)
test.OK(t, runInit(opts, nil)) rtest.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)
test.OK(t, runBackup(opts, gopts, target)) rtest.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 {
@ -62,7 +62,7 @@ func testRunList(t testing.TB, tpe string, opts GlobalOptions) restic.IDs {
globalOptions.stdout = os.Stdout globalOptions.stdout = os.Stdout
}() }()
test.OK(t, runList(opts, []string{tpe})) rtest.OK(t, runList(opts, []string{tpe}))
return parseIDsFromReader(t, buf) return parseIDsFromReader(t, buf)
} }
@ -77,7 +77,7 @@ func testRunRestoreLatest(t testing.TB, gopts GlobalOptions, dir string, paths [
Paths: paths, Paths: paths,
} }
test.OK(t, runRestore(opts, gopts, []string{"latest"})) rtest.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) {
@ -86,7 +86,7 @@ func testRunRestoreExcludes(t testing.TB, gopts GlobalOptions, dir string, snaps
Exclude: excludes, Exclude: excludes,
} }
test.OK(t, runRestore(opts, gopts, []string{snapshotID.String()})) rtest.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) {
@ -95,7 +95,7 @@ func testRunRestoreIncludes(t testing.TB, gopts GlobalOptions, dir string, snaps
Include: includes, Include: includes,
} }
test.OK(t, runRestore(opts, gopts, []string{snapshotID.String()})) rtest.OK(t, runRestore(opts, gopts, []string{snapshotID.String()}))
} }
func testRunCheck(t testing.TB, gopts GlobalOptions) { func testRunCheck(t testing.TB, gopts GlobalOptions) {
@ -103,7 +103,7 @@ func testRunCheck(t testing.TB, gopts GlobalOptions) {
ReadData: true, ReadData: true,
CheckUnused: true, CheckUnused: true,
} }
test.OK(t, runCheck(opts, gopts, nil)) rtest.OK(t, runCheck(opts, gopts, nil))
} }
func testRunCheckOutput(gopts GlobalOptions) (string, error) { func testRunCheckOutput(gopts GlobalOptions) (string, error) {
@ -128,7 +128,7 @@ func testRunRebuildIndex(t testing.TB, gopts GlobalOptions) {
globalOptions.stdout = os.Stdout globalOptions.stdout = os.Stdout
}() }()
test.OK(t, runRebuildIndex(gopts)) rtest.OK(t, runRebuildIndex(gopts))
} }
func testRunLs(t testing.TB, gopts GlobalOptions, snapshotID string) []string { func testRunLs(t testing.TB, gopts GlobalOptions, snapshotID string) []string {
@ -143,7 +143,7 @@ func testRunLs(t testing.TB, gopts GlobalOptions, snapshotID string) []string {
opts := LsOptions{} opts := LsOptions{}
test.OK(t, runLs(opts, gopts, []string{snapshotID})) rtest.OK(t, runLs(opts, gopts, []string{snapshotID}))
return strings.Split(string(buf.Bytes()), "\n") return strings.Split(string(buf.Bytes()), "\n")
} }
@ -159,7 +159,7 @@ func testRunFind(t testing.TB, wantJSON bool, gopts GlobalOptions, pattern strin
opts := FindOptions{} opts := FindOptions{}
test.OK(t, runFind(opts, gopts, []string{pattern})) rtest.OK(t, runFind(opts, gopts, []string{pattern}))
return buf.Bytes() return buf.Bytes()
} }
@ -175,10 +175,10 @@ func testRunSnapshots(t testing.TB, gopts GlobalOptions) (newest *Snapshot, snap
opts := SnapshotOptions{} opts := SnapshotOptions{}
test.OK(t, runSnapshots(opts, globalOptions, []string{})) rtest.OK(t, runSnapshots(opts, globalOptions, []string{}))
snapshots := []Snapshot{} snapshots := []Snapshot{}
test.OK(t, json.Unmarshal(buf.Bytes(), &snapshots)) rtest.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 {
@ -192,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{}
test.OK(t, runForget(opts, gopts, args)) rtest.OK(t, runForget(opts, gopts, args))
} }
func testRunPrune(t testing.TB, gopts GlobalOptions) { func testRunPrune(t testing.TB, gopts GlobalOptions) {
test.OK(t, runPrune(gopts)) rtest.OK(t, runPrune(gopts))
} }
func TestBackup(t *testing.T) { func TestBackup(t *testing.T) {
@ -209,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
} }
test.OK(t, err) rtest.OK(t, err)
test.OK(t, fd.Close()) rtest.OK(t, fd.Close())
testRunInit(t, env.gopts) testRunInit(t, env.gopts)
test.SetupTarTestFixture(t, env.testdata, datafile) rtest.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)
test.Assert(t, len(snapshotIDs) == 1, rtest.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)
@ -229,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)
test.Assert(t, len(snapshotIDs) == 2, rtest.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)
@ -243,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)
test.Assert(t, len(snapshotIDs) == 3, rtest.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)
@ -257,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])
test.Assert(t, directoriesEqualContents(env.testdata, filepath.Join(restoredir, "testdata")), rtest.Assert(t, directoriesEqualContents(env.testdata, filepath.Join(restoredir, "testdata")),
"directories are not equal") "directories are not equal")
} }
@ -274,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
} }
test.OK(t, err) rtest.OK(t, err)
test.OK(t, fd.Close()) rtest.OK(t, fd.Close())
test.SetupTarTestFixture(t, env.testdata, datafile) rtest.SetupTarTestFixture(t, env.testdata, datafile)
testRunInit(t, env.gopts) testRunInit(t, env.gopts)
globalOptions.stderr = ioutil.Discard globalOptions.stderr = ioutil.Discard
@ -308,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
} }
test.OK(t, err) rtest.OK(t, err)
test.OK(t, fd.Close()) rtest.OK(t, fd.Close())
test.SetupTarTestFixture(t, env.testdata, datafile) rtest.SetupTarTestFixture(t, env.testdata, datafile)
testRunInit(t, env.gopts) testRunInit(t, env.gopts)
globalOptions.stderr = ioutil.Discard globalOptions.stderr = ioutil.Discard
@ -330,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
test.OK(t, os.Remove(filepath.Join(env.testdata, "0", "0", "9", "37"))) rtest.OK(t, os.Remove(filepath.Join(env.testdata, "0", "0", "9", "37")))
}) })
opts := BackupOptions{} opts := BackupOptions{}
@ -338,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)
test.Assert(t, ranHook, "hook did not run") rtest.Assert(t, ranHook, "hook did not run")
debug.RemoveHook("pipe.walk1") debug.RemoveHook("pipe.walk1")
} }
@ -352,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
} }
test.OK(t, err) rtest.OK(t, err)
test.OK(t, fd.Close()) rtest.OK(t, fd.Close())
test.SetupTarTestFixture(t, env.testdata, datafile) rtest.SetupTarTestFixture(t, env.testdata, datafile)
testRunInit(t, env.gopts) testRunInit(t, env.gopts)
@ -375,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
test.OK(t, os.Remove(filepath.Join(env.testdata, "0", "0", "9", "37"))) rtest.OK(t, os.Remove(filepath.Join(env.testdata, "0", "0", "9", "37")))
}) })
opts := BackupOptions{} opts := BackupOptions{}
@ -383,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)
test.Assert(t, ranHook, "hook did not run") rtest.Assert(t, ranHook, "hook did not run")
debug.RemoveHook("pipe.walk2") debug.RemoveHook("pipe.walk2")
} }
@ -397,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
} }
test.OK(t, err) rtest.OK(t, err)
test.OK(t, fd.Close()) rtest.OK(t, fd.Close())
test.SetupTarTestFixture(t, env.testdata, datafile) rtest.SetupTarTestFixture(t, env.testdata, datafile)
testRunInit(t, env.gopts) testRunInit(t, env.gopts)
@ -422,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
test.OK(t, ioutil.WriteFile(modFile, []byte("modified"), 0600)) rtest.OK(t, ioutil.WriteFile(modFile, []byte("modified"), 0600))
}) })
opts := BackupOptions{} opts := BackupOptions{}
@ -430,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)
test.Assert(t, ranHook, "hook did not run") rtest.Assert(t, ranHook, "hook did not run")
debug.RemoveHook("archiver.SaveFile") debug.RemoveHook("archiver.SaveFile")
} }
@ -444,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
} }
test.OK(t, err) rtest.OK(t, err)
test.OK(t, fd.Close()) rtest.OK(t, fd.Close())
test.SetupTarTestFixture(t, env.testdata, datafile) rtest.SetupTarTestFixture(t, env.testdata, datafile)
testRunInit(t, env.gopts) testRunInit(t, env.gopts)
@ -471,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
test.OK(t, os.RemoveAll(testdir)) rtest.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)
test.Assert(t, ranHook, "hook did not run") rtest.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)
test.Assert(t, len(snapshots) > 0, rtest.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())
test.Assert(t, len(files) > 1, "snapshot is empty") rtest.Assert(t, len(files) > 1, "snapshot is empty")
} }
func includes(haystack []string, needle string) bool { func includes(haystack []string, needle string) bool {
@ -538,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)
test.OK(t, os.MkdirAll(filepath.Dir(fp), 0755)) rtest.OK(t, os.MkdirAll(filepath.Dir(fp), 0755))
f, err := os.Create(fp) f, err := os.Create(fp)
test.OK(t, err) rtest.OK(t, err)
fmt.Fprintf(f, filename) fmt.Fprintf(f, filename)
test.OK(t, f.Close()) rtest.OK(t, f.Close())
} }
snapshots := make(map[string]struct{}) snapshots := make(map[string]struct{})
@ -554,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)
test.Assert(t, includes(files, filepath.Join(string(filepath.Separator), "testdata", "foo.tar.gz")), rtest.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)
test.Assert(t, !includes(files, filepath.Join(string(filepath.Separator), "testdata", "foo.tar.gz")), rtest.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)
test.Assert(t, !includes(files, filepath.Join(string(filepath.Separator), "testdata", "foo.tar.gz")), rtest.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")
test.Assert(t, !includes(files, filepath.Join(string(filepath.Separator), "testdata", "private", "secret", "passwords.txt")), rtest.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")
} }
@ -611,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")
test.OK(t, appendRandomData(testfile, incrementalFirstWrite)) rtest.OK(t, appendRandomData(testfile, incrementalFirstWrite))
opts := BackupOptions{} opts := BackupOptions{}
@ -619,7 +619,7 @@ func TestIncrementalBackup(t *testing.T) {
testRunCheck(t, env.gopts) testRunCheck(t, env.gopts)
stat1 := dirStats(env.repo) stat1 := dirStats(env.repo)
test.OK(t, appendRandomData(testfile, incrementalSecondWrite)) rtest.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)
@ -629,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)
test.OK(t, appendRandomData(testfile, incrementalThirdWrite)) rtest.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)
@ -646,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)
test.SetupTarTestFixture(t, env.testdata, datafile) rtest.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)
test.Assert(t, newest != nil, "expected a new backup, got nil") rtest.Assert(t, newest != nil, "expected a new backup, got nil")
test.Assert(t, len(newest.Tags) == 0, rtest.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)
test.Assert(t, newest != nil, "expected a new backup, got nil") rtest.Assert(t, newest != nil, "expected a new backup, got nil")
test.Assert(t, len(newest.Tags) == 1 && newest.Tags[0] == "NL", rtest.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) {
test.OK(t, runTag(opts, gopts, []string{})) rtest.OK(t, runTag(opts, gopts, []string{}))
} }
func TestTag(t *testing.T) { func TestTag(t *testing.T) {
@ -676,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)
test.SetupTarTestFixture(t, env.testdata, datafile) rtest.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)
test.Assert(t, newest != nil, "expected a new backup, got nil") rtest.Assert(t, newest != nil, "expected a new backup, got nil")
test.Assert(t, len(newest.Tags) == 0, rtest.Assert(t, len(newest.Tags) == 0,
"expected no tags, got %v", newest.Tags) "expected no tags, got %v", newest.Tags)
test.Assert(t, newest.Original == nil, rtest.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)
test.Assert(t, newest != nil, "expected a new backup, got nil") rtest.Assert(t, newest != nil, "expected a new backup, got nil")
test.Assert(t, len(newest.Tags) == 1 && newest.Tags[0] == "NL", rtest.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)
test.Assert(t, newest.Original != nil, "expected original snapshot id, got nil") rtest.Assert(t, newest.Original != nil, "expected original snapshot id, got nil")
test.Assert(t, *newest.Original == originalID, rtest.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)
test.Assert(t, newest != nil, "expected a new backup, got nil") rtest.Assert(t, newest != nil, "expected a new backup, got nil")
test.Assert(t, len(newest.Tags) == 2 && newest.Tags[0] == "NL" && newest.Tags[1] == "CH", rtest.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)
test.Assert(t, newest.Original != nil, "expected original snapshot id, got nil") rtest.Assert(t, newest.Original != nil, "expected original snapshot id, got nil")
test.Assert(t, *newest.Original == originalID, rtest.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)
test.Assert(t, newest != nil, "expected a new backup, got nil") rtest.Assert(t, newest != nil, "expected a new backup, got nil")
test.Assert(t, len(newest.Tags) == 1 && newest.Tags[0] == "CH", rtest.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)
test.Assert(t, newest.Original != nil, "expected original snapshot id, got nil") rtest.Assert(t, newest.Original != nil, "expected original snapshot id, got nil")
test.Assert(t, *newest.Original == originalID, rtest.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)
test.Assert(t, newest != nil, "expected a new backup, got nil") rtest.Assert(t, newest != nil, "expected a new backup, got nil")
test.Assert(t, len(newest.Tags) == 0, rtest.Assert(t, len(newest.Tags) == 0,
"expected no tags, got %v", newest.Tags) "expected no tags, got %v", newest.Tags)
test.Assert(t, newest.Original != nil, "expected original snapshot id, got nil") rtest.Assert(t, newest.Original != nil, "expected original snapshot id, got nil")
test.Assert(t, *newest.Original == originalID, rtest.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)
test.Assert(t, newest != nil, "expected a new backup, got nil") rtest.Assert(t, newest != nil, "expected a new backup, got nil")
test.Assert(t, len(newest.Tags) == 0, rtest.Assert(t, len(newest.Tags) == 0,
"expected no tags, got %v", newest.Tags) "expected no tags, got %v", newest.Tags)
test.Assert(t, newest.Original != nil, "expected original snapshot id, got nil") rtest.Assert(t, newest.Original != nil, "expected original snapshot id, got nil")
test.Assert(t, *newest.Original == originalID, rtest.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")
} }
@ -749,7 +749,7 @@ func testRunKeyListOtherIDs(t testing.TB, gopts GlobalOptions) []string {
globalOptions.stdout = os.Stdout globalOptions.stdout = os.Stdout
}() }()
test.OK(t, runKey(gopts, []string{"list"})) rtest.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]+) `)
@ -770,7 +770,7 @@ func testRunKeyAddNewKey(t testing.TB, newPassword string, gopts GlobalOptions)
testKeyNewPassword = "" testKeyNewPassword = ""
}() }()
test.OK(t, runKey(gopts, []string{"add"})) rtest.OK(t, runKey(gopts, []string{"add"}))
} }
func testRunKeyPasswd(t testing.TB, newPassword string, gopts GlobalOptions) { func testRunKeyPasswd(t testing.TB, newPassword string, gopts GlobalOptions) {
@ -779,13 +779,13 @@ func testRunKeyPasswd(t testing.TB, newPassword string, gopts GlobalOptions) {
testKeyNewPassword = "" testKeyNewPassword = ""
}() }()
test.OK(t, runKey(gopts, []string{"passwd"})) rtest.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 {
test.OK(t, runKey(gopts, []string{"remove", id})) rtest.OK(t, runKey(gopts, []string{"remove", id}))
} }
} }
@ -813,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)
test.OK(t, runKey(env.gopts, []string{"list"})) rtest.OK(t, runKey(env.gopts, []string{"list"}))
testRunCheck(t, env.gopts) testRunCheck(t, env.gopts)
} }
@ -848,8 +848,8 @@ func TestRestoreFilter(t *testing.T) {
for _, testFile := range testfiles { for _, testFile := range testfiles {
p := filepath.Join(env.testdata, testFile.name) p := filepath.Join(env.testdata, testFile.name)
test.OK(t, os.MkdirAll(filepath.Dir(p), 0755)) rtest.OK(t, os.MkdirAll(filepath.Dir(p), 0755))
test.OK(t, appendRandomData(p, testFile.size)) rtest.OK(t, appendRandomData(p, testFile.size))
} }
opts := BackupOptions{} opts := BackupOptions{}
@ -862,7 +862,7 @@ 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 _, testFile := range testfiles { for _, testFile := range testfiles {
test.OK(t, testFileSize(filepath.Join(env.base, "restore0", "testdata", testFile.name), int64(testFile.size))) rtest.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*"} {
@ -871,9 +871,9 @@ func TestRestoreFilter(t *testing.T) {
for _, testFile := range testfiles { for _, testFile := range testfiles {
err := testFileSize(filepath.Join(base, "testdata", testFile.name), int64(testFile.size)) err := testFileSize(filepath.Join(base, "testdata", testFile.name), int64(testFile.size))
if ok, _ := filter.Match(pat, filepath.Base(testFile.name)); !ok { if ok, _ := filter.Match(pat, filepath.Base(testFile.name)); !ok {
test.OK(t, err) rtest.OK(t, err)
} else { } else {
test.Assert(t, os.IsNotExist(errors.Cause(err)), rtest.Assert(t, os.IsNotExist(errors.Cause(err)),
"expected %v to not exist in restore step %v, but it exists, err %v", testFile.name, i+1, err) "expected %v to not exist in restore step %v, but it exists, err %v", testFile.name, i+1, err)
} }
} }
@ -888,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))
test.OK(t, os.MkdirAll(filepath.Dir(p), 0755)) rtest.OK(t, os.MkdirAll(filepath.Dir(p), 0755))
test.OK(t, appendRandomData(p, uint(mrand.Intn(5<<21)))) rtest.OK(t, appendRandomData(p, uint(mrand.Intn(5<<21))))
} }
opts := BackupOptions{} opts := BackupOptions{}
@ -901,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, "")
test.Assert(t, directoriesEqualContents(env.testdata, filepath.Join(restoredir, filepath.Base(env.testdata))), rtest.Assert(t, directoriesEqualContents(env.testdata, filepath.Join(restoredir, filepath.Base(env.testdata))),
"directories are not equal") "directories are not equal")
} }
@ -912,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")
test.OK(t, os.MkdirAll(filepath.Dir(p), 0755)) rtest.OK(t, os.MkdirAll(filepath.Dir(p), 0755))
test.OK(t, appendRandomData(p, 100)) rtest.OK(t, appendRandomData(p, 100))
opts := BackupOptions{} opts := BackupOptions{}
@ -921,24 +921,24 @@ func TestRestoreLatest(t *testing.T) {
testRunCheck(t, env.gopts) testRunCheck(t, env.gopts)
os.Remove(p) os.Remove(p)
test.OK(t, appendRandomData(p, 101)) rtest.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, "")
test.OK(t, testFileSize(filepath.Join(env.base, "restore0", "testdata", "testfile.c"), int64(101))) rtest.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")
test.OK(t, os.MkdirAll(filepath.Dir(p1), 0755)) rtest.OK(t, os.MkdirAll(filepath.Dir(p1), 0755))
test.OK(t, appendRandomData(p1, 102)) rtest.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")
test.OK(t, os.MkdirAll(filepath.Dir(p2), 0755)) rtest.OK(t, os.MkdirAll(filepath.Dir(p2), 0755))
test.OK(t, appendRandomData(p2, 103)) rtest.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)
@ -946,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)}, "")
test.OK(t, testFileSize(p1rAbs, int64(102))) rtest.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)) {
test.Assert(t, os.IsNotExist(errors.Cause(err)), rtest.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)}, "")
test.OK(t, testFileSize(p2rAbs, int64(103))) rtest.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)) {
test.Assert(t, os.IsNotExist(errors.Cause(err)), rtest.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)
} }
} }
@ -965,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")
test.SetupTarTestFixture(t, env.base, datafile) rtest.SetupTarTestFixture(t, env.base, datafile)
snapshots := testRunList(t, "snapshots", env.gopts) snapshots := testRunList(t, "snapshots", env.gopts)
test.Assert(t, len(snapshots) > 0, rtest.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
@ -983,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))
test.OK(t, err) rtest.OK(t, err)
test.Assert(t, !isFile(fi) || fi.Size() > 0, rtest.Assert(t, !isFile(fi) || fi.Size() > 0,
"file %v restored, but filesize is 0", filename) "file %v restored, but filesize is 0", filename)
} }
} }
@ -1006,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")
test.OK(t, os.MkdirAll(filepath.Dir(p), 0755)) rtest.OK(t, os.MkdirAll(filepath.Dir(p), 0755))
test.OK(t, appendRandomData(p, 200)) rtest.OK(t, appendRandomData(p, 200))
test.OK(t, setZeroModTime(filepath.Join(env.testdata, "subdir1", "subdir2"))) rtest.OK(t, setZeroModTime(filepath.Join(env.testdata, "subdir1", "subdir2")))
opts := BackupOptions{} opts := BackupOptions{}
@ -1024,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)
test.OK(t, err) rtest.OK(t, err)
test.Assert(t, fi.ModTime() != time.Unix(0, 0), rtest.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.
@ -1034,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)
test.OK(t, err) rtest.OK(t, err)
test.Assert(t, fi.ModTime() == time.Unix(0, 0), rtest.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")
} }
@ -1046,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)
test.SetupTarTestFixture(t, env.testdata, datafile) rtest.SetupTarTestFixture(t, env.testdata, datafile)
opts := BackupOptions{} opts := BackupOptions{}
@ -1054,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")
test.Assert(t, len(results) == 0, "unexisting file found in repo (%v)", datafile) rtest.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")
test.Assert(t, len(lines) == 2, "expected one file found in repo (%v)", datafile) rtest.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")
test.Assert(t, len(lines) == 4, "expected three files found in repo (%v)", datafile) rtest.Assert(t, len(lines) == 4, "expected three files found in repo (%v)", datafile)
} }
type testMatch struct { type testMatch struct {
@ -1086,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)
test.SetupTarTestFixture(t, env.testdata, datafile) rtest.SetupTarTestFixture(t, env.testdata, datafile)
opts := BackupOptions{} opts := BackupOptions{}
@ -1095,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{}
test.OK(t, json.Unmarshal(results, &matches)) rtest.OK(t, json.Unmarshal(results, &matches))
test.Assert(t, len(matches) == 0, "expected no match in repo (%v)", datafile) rtest.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")
test.OK(t, json.Unmarshal(results, &matches)) rtest.OK(t, json.Unmarshal(results, &matches))
test.Assert(t, len(matches) == 1, "expected a single snapshot in repo (%v)", datafile) rtest.Assert(t, len(matches) == 1, "expected a single snapshot in repo (%v)", datafile)
test.Assert(t, len(matches[0].Matches) == 1, "expected a single file to match (%v)", datafile) rtest.Assert(t, len(matches[0].Matches) == 1, "expected a single file to match (%v)", datafile)
test.Assert(t, matches[0].Hits == 1, "expected hits to show 1 match (%v)", datafile) rtest.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*")
test.OK(t, json.Unmarshal(results, &matches)) rtest.OK(t, json.Unmarshal(results, &matches))
test.Assert(t, len(matches) == 1, "expected a single snapshot in repo (%v)", datafile) rtest.Assert(t, len(matches) == 1, "expected a single snapshot in repo (%v)", datafile)
test.Assert(t, len(matches[0].Matches) == 3, "expected 3 files to match (%v)", datafile) rtest.Assert(t, len(matches[0].Matches) == 3, "expected 3 files to match (%v)", datafile)
test.Assert(t, matches[0].Hits == 3, "expected hits to show 3 matches (%v)", datafile) rtest.Assert(t, matches[0].Hits == 3, "expected hits to show 3 matches (%v)", datafile)
} }
func TestRebuildIndex(t *testing.T) { func TestRebuildIndex(t *testing.T) {
@ -1116,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")
test.SetupTarTestFixture(t, env.base, datafile) rtest.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") {
@ -1153,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")
test.SetupTarTestFixture(t, env.base, datafile) rtest.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 {
@ -1161,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)))
}) })
test.OK(t, err) rtest.OK(t, err)
env.gopts.NoLock = true env.gopts.NoLock = true
@ -1185,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
} }
test.OK(t, err) rtest.OK(t, err)
test.OK(t, fd.Close()) rtest.OK(t, fd.Close())
testRunInit(t, env.gopts) testRunInit(t, env.gopts)
test.SetupTarTestFixture(t, env.testdata, datafile) rtest.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)
test.Assert(t, len(firstSnapshot) == 1, rtest.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)
test.Assert(t, len(snapshotIDs) == 3, rtest.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())
@ -1221,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
} }
test.OK(t, err) rtest.OK(t, err)
test.OK(t, fd.Close()) rtest.OK(t, fd.Close())
testRunInit(t, env.gopts) testRunInit(t, env.gopts)
test.SetupTarTestFixture(t, env.testdata, datafile) rtest.SetupTarTestFixture(t, env.testdata, datafile)
linkTests := createFileSetPerHardlink(env.testdata) linkTests := createFileSetPerHardlink(env.testdata)
@ -1235,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)
test.Assert(t, len(snapshotIDs) == 1, rtest.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)
@ -1245,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])
test.Assert(t, directoriesEqualContents(env.testdata, filepath.Join(restoredir, "testdata")), rtest.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"))
test.Assert(t, linksEqual(linkTests, linkResults), rtest.Assert(t, linksEqual(linkTests, linkResults),
"links are not equal") "links are not equal")
} }