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

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

View File

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

View File

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

View File

@@ -10,7 +10,7 @@ import (
"time"
"github.com/restic/restic/internal/restic"
. "github.com/restic/restic/internal/test"
rtest "github.com/restic/restic/internal/test"
)
func BenchmarkNodeFillUser(t *testing.B) {
@@ -32,8 +32,8 @@ func BenchmarkNodeFillUser(t *testing.B) {
restic.NodeFromFileInfo(path, fi)
}
OK(t, tempfile.Close())
RemoveAll(t, tempfile.Name())
rtest.OK(t, tempfile.Close())
rtest.RemoveAll(t, tempfile.Name())
}
func BenchmarkNodeFromFileInfo(t *testing.B) {
@@ -58,8 +58,8 @@ func BenchmarkNodeFromFileInfo(t *testing.B) {
}
}
OK(t, tempfile.Close())
RemoveAll(t, tempfile.Name())
rtest.OK(t, tempfile.Close())
rtest.RemoveAll(t, tempfile.Name())
}
func parseTime(s string) time.Time {
@@ -166,12 +166,12 @@ var nodeTests = []restic.Node{
}
func TestNodeRestoreAt(t *testing.T) {
tempdir, err := ioutil.TempDir(TestTempDir, "restic-test-")
OK(t, err)
tempdir, err := ioutil.TempDir(rtest.TestTempDir, "restic-test-")
rtest.OK(t, err)
defer func() {
if TestCleanupTempDirs {
RemoveAll(t, tempdir)
if rtest.TestCleanupTempDirs {
rtest.RemoveAll(t, tempdir)
} else {
t.Logf("leaving tempdir at %v", tempdir)
}
@@ -181,35 +181,35 @@ func TestNodeRestoreAt(t *testing.T) {
for _, test := range nodeTests {
nodePath := filepath.Join(tempdir, test.Name)
OK(t, test.CreateAt(context.TODO(), nodePath, nil, idx))
rtest.OK(t, test.CreateAt(context.TODO(), nodePath, nil, idx))
if test.Type == "symlink" && runtime.GOOS == "windows" {
continue
}
if test.Type == "dir" {
OK(t, test.RestoreTimestamps(nodePath))
rtest.OK(t, test.RestoreTimestamps(nodePath))
}
fi, err := os.Lstat(nodePath)
OK(t, err)
rtest.OK(t, err)
n2, err := restic.NodeFromFileInfo(nodePath, fi)
OK(t, err)
rtest.OK(t, err)
Assert(t, test.Name == n2.Name,
rtest.Assert(t, test.Name == n2.Name,
"%v: name doesn't match (%v != %v)", test.Type, test.Name, n2.Name)
Assert(t, test.Type == n2.Type,
rtest.Assert(t, test.Type == n2.Type,
"%v: type doesn't match (%v != %v)", test.Type, test.Type, n2.Type)
Assert(t, test.Size == n2.Size,
rtest.Assert(t, test.Size == n2.Size,
"%v: size doesn't match (%v != %v)", test.Size, test.Size, n2.Size)
if runtime.GOOS != "windows" {
Assert(t, test.UID == n2.UID,
rtest.Assert(t, test.UID == n2.UID,
"%v: UID doesn't match (%v != %v)", test.Type, test.UID, n2.UID)
Assert(t, test.GID == n2.GID,
rtest.Assert(t, test.GID == n2.GID,
"%v: GID doesn't match (%v != %v)", test.Type, test.GID, n2.GID)
if test.Type != "symlink" {
Assert(t, test.Mode == n2.Mode,
rtest.Assert(t, test.Mode == n2.Mode,
"%v: mode doesn't match (0%o != 0%o)", test.Type, test.Mode, n2.Mode)
}
}
@@ -240,5 +240,5 @@ func AssertFsTimeEqual(t *testing.T, label string, nodeType string, t1 time.Time
equal = t1.Equal(t2)
}
Assert(t, equal, "%s: %s doesn't match (%v != %v)", label, nodeType, t1, t2)
rtest.Assert(t, equal, "%s: %s doesn't match (%v != %v)", label, nodeType, t1, t2)
}

View File

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

View File

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