Remove SetupRepo

This commit is contained in:
Alexander Neumann 2016-09-04 13:24:51 +02:00
parent f5b9ee53a3
commit 6ab425f130
7 changed files with 29 additions and 68 deletions

View File

@ -10,6 +10,7 @@ import (
"restic/archiver"
"restic/checker"
"restic/crypto"
"restic/repository"
. "restic/test"
"restic/errors"
@ -47,7 +48,7 @@ func benchmarkChunkEncrypt(b testing.TB, buf, buf2 []byte, rd Rdr, key *crypto.K
}
func BenchmarkChunkEncrypt(b *testing.B) {
repo, cleanup := SetupRepo(b)
repo, cleanup := repository.TestRepository(b)
defer cleanup()
data := Random(23, 10<<20) // 10MiB
@ -79,7 +80,7 @@ func benchmarkChunkEncryptP(b *testing.PB, buf []byte, rd Rdr, key *crypto.Key)
}
func BenchmarkChunkEncryptParallel(b *testing.B) {
repo, cleanup := SetupRepo(b)
repo, cleanup := repository.TestRepository(b)
defer cleanup()
data := Random(23, 10<<20) // 10MiB
@ -98,7 +99,7 @@ func BenchmarkChunkEncryptParallel(b *testing.B) {
}
func archiveDirectory(b testing.TB) {
repo, cleanup := SetupRepo(b)
repo, cleanup := repository.TestRepository(b)
defer cleanup()
arch := archiver.New(repo)
@ -136,7 +137,7 @@ func countPacks(repo restic.Repository, t restic.FileType) (n uint) {
}
func archiveWithDedup(t testing.TB) {
repo, cleanup := SetupRepo(t)
repo, cleanup := repository.TestRepository(t)
defer cleanup()
if BenchArchiveDirectory == "" {
@ -208,7 +209,7 @@ func TestParallelSaveWithDuplication(t *testing.T) {
}
func testParallelSaveWithDuplication(t *testing.T, seed int) {
repo, cleanup := SetupRepo(t)
repo, cleanup := repository.TestRepository(t)
defer cleanup()
dataSizeMb := 128

View File

@ -4,9 +4,10 @@ import (
"crypto/rand"
"time"
"restic/errors"
sscrypt "github.com/elithrar/simple-scrypt"
"golang.org/x/crypto/scrypt"
"restic/errors"
)
const saltLength = 64

View File

@ -6,11 +6,12 @@ import (
"time"
"restic"
"restic/repository"
. "restic/test"
)
func TestLock(t *testing.T) {
repo, cleanup := SetupRepo(t)
repo, cleanup := repository.TestRepository(t)
defer cleanup()
lock, err := restic.NewLock(repo)
@ -20,7 +21,7 @@ func TestLock(t *testing.T) {
}
func TestDoubleUnlock(t *testing.T) {
repo, cleanup := SetupRepo(t)
repo, cleanup := repository.TestRepository(t)
defer cleanup()
lock, err := restic.NewLock(repo)
@ -34,7 +35,7 @@ func TestDoubleUnlock(t *testing.T) {
}
func TestMultipleLock(t *testing.T) {
repo, cleanup := SetupRepo(t)
repo, cleanup := repository.TestRepository(t)
defer cleanup()
lock1, err := restic.NewLock(repo)
@ -48,7 +49,7 @@ func TestMultipleLock(t *testing.T) {
}
func TestLockExclusive(t *testing.T) {
repo, cleanup := SetupRepo(t)
repo, cleanup := repository.TestRepository(t)
defer cleanup()
elock, err := restic.NewExclusiveLock(repo)
@ -57,7 +58,7 @@ func TestLockExclusive(t *testing.T) {
}
func TestLockOnExclusiveLockedRepo(t *testing.T) {
repo, cleanup := SetupRepo(t)
repo, cleanup := repository.TestRepository(t)
defer cleanup()
elock, err := restic.NewExclusiveLock(repo)
@ -74,7 +75,7 @@ func TestLockOnExclusiveLockedRepo(t *testing.T) {
}
func TestExclusiveLockOnLockedRepo(t *testing.T) {
repo, cleanup := SetupRepo(t)
repo, cleanup := repository.TestRepository(t)
defer cleanup()
elock, err := restic.NewLock(repo)
@ -168,7 +169,7 @@ func lockExists(repo restic.Repository, t testing.TB, id restic.ID) bool {
}
func TestLockWithStaleLock(t *testing.T) {
repo, cleanup := SetupRepo(t)
repo, cleanup := repository.TestRepository(t)
defer cleanup()
id1, err := createFakeLock(repo, time.Now().Add(-time.Hour), os.Getpid())
@ -193,7 +194,7 @@ func TestLockWithStaleLock(t *testing.T) {
}
func TestRemoveAllLocks(t *testing.T) {
repo, cleanup := SetupRepo(t)
repo, cleanup := repository.TestRepository(t)
defer cleanup()
id1, err := createFakeLock(repo, time.Now().Add(-time.Hour), os.Getpid())
@ -216,7 +217,7 @@ func TestRemoveAllLocks(t *testing.T) {
}
func TestLockRefresh(t *testing.T) {
repo, cleanup := SetupRepo(t)
repo, cleanup := repository.TestRepository(t)
defer cleanup()
lock, err := restic.NewLock(repo)

View File

@ -18,7 +18,7 @@ import (
var testSizes = []int{5, 23, 2<<18 + 23, 1 << 20}
func TestSave(t *testing.T) {
repo, cleanup := SetupRepo(t)
repo, cleanup := repository.TestRepository(t)
defer cleanup()
for _, size := range testSizes {
@ -54,7 +54,7 @@ func TestSave(t *testing.T) {
}
func TestSaveFrom(t *testing.T) {
repo, cleanup := SetupRepo(t)
repo, cleanup := repository.TestRepository(t)
defer cleanup()
for _, size := range testSizes {
@ -88,7 +88,7 @@ func TestSaveFrom(t *testing.T) {
}
func BenchmarkSaveAndEncrypt(t *testing.B) {
repo, cleanup := SetupRepo(t)
repo, cleanup := repository.TestRepository(t)
defer cleanup()
size := 4 << 20 // 4MiB
@ -110,7 +110,7 @@ func BenchmarkSaveAndEncrypt(t *testing.B) {
}
func TestLoadTree(t *testing.T) {
repo, cleanup := SetupRepo(t)
repo, cleanup := repository.TestRepository(t)
defer cleanup()
if BenchArchiveDirectory == "" {
@ -126,7 +126,7 @@ func TestLoadTree(t *testing.T) {
}
func BenchmarkLoadTree(t *testing.B) {
repo, cleanup := SetupRepo(t)
repo, cleanup := repository.TestRepository(t)
defer cleanup()
if BenchArchiveDirectory == "" {
@ -146,7 +146,7 @@ func BenchmarkLoadTree(t *testing.B) {
}
func TestLoadJSONUnpacked(t *testing.T) {
repo, cleanup := SetupRepo(t)
repo, cleanup := repository.TestRepository(t)
defer cleanup()
if BenchArchiveDirectory == "" {
@ -207,7 +207,7 @@ func saveRandomDataBlobs(t testing.TB, repo restic.Repository, num int, sizeMax
}
func TestRepositoryIncrementalIndex(t *testing.T) {
repo, cleanup := SetupRepo(t)
repo, cleanup := repository.TestRepository(t)
defer cleanup()
repository.IndexFull = func(*repository.Index) bool { return true }

View File

@ -2,14 +2,7 @@ package test_helper
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
"restic"
"restic/backend/local"
"restic/repository"
)
var (
@ -47,40 +40,3 @@ func getBoolVar(name string, defaultValue bool) bool {
return defaultValue
}
// SetupRepo returns a repo setup in a temp dir.
func SetupRepo(t testing.TB) (repo restic.Repository, cleanup func()) {
tempdir, err := ioutil.TempDir(TestTempDir, "restic-test-")
if err != nil {
t.Fatal(err)
}
// create repository below temp dir
b, err := local.Create(filepath.Join(tempdir, "repo"))
if err != nil {
t.Fatal(err)
}
r := repository.New(b)
err = r.Init(TestPassword)
if err != nil {
t.Fatal(err)
}
repo = r
cleanup = func() {
if !TestCleanupTempDirs {
l := repo.Backend().(*local.Local)
fmt.Printf("leaving local backend at %s\n", l.Location())
return
}
if r, ok := repo.(restic.Deleter); ok {
err := r.Delete()
if err != nil {
t.Fatal(err)
}
}
}
return repo, cleanup
}

View File

@ -8,6 +8,7 @@ import (
"testing"
"restic"
"restic/repository"
. "restic/test"
)
@ -92,7 +93,7 @@ func TestNodeComparison(t *testing.T) {
}
func TestLoadTree(t *testing.T) {
repo, cleanup := SetupRepo(t)
repo, cleanup := repository.TestRepository(t)
defer cleanup()
// save tree

View File

@ -10,12 +10,13 @@ import (
"restic"
"restic/archiver"
"restic/pipe"
"restic/repository"
. "restic/test"
"restic/walk"
)
func TestWalkTree(t *testing.T) {
repo, cleanup := SetupRepo(t)
repo, cleanup := repository.TestRepository(t)
defer cleanup()
dirs, err := filepath.Glob(TestWalkerPath)