2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-26 23:06:32 +00:00

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

View File

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

View File

@ -6,11 +6,12 @@ import (
"time" "time"
"restic" "restic"
"restic/repository"
. "restic/test" . "restic/test"
) )
func TestLock(t *testing.T) { func TestLock(t *testing.T) {
repo, cleanup := SetupRepo(t) repo, cleanup := repository.TestRepository(t)
defer cleanup() defer cleanup()
lock, err := restic.NewLock(repo) lock, err := restic.NewLock(repo)
@ -20,7 +21,7 @@ func TestLock(t *testing.T) {
} }
func TestDoubleUnlock(t *testing.T) { func TestDoubleUnlock(t *testing.T) {
repo, cleanup := SetupRepo(t) repo, cleanup := repository.TestRepository(t)
defer cleanup() defer cleanup()
lock, err := restic.NewLock(repo) lock, err := restic.NewLock(repo)
@ -34,7 +35,7 @@ func TestDoubleUnlock(t *testing.T) {
} }
func TestMultipleLock(t *testing.T) { func TestMultipleLock(t *testing.T) {
repo, cleanup := SetupRepo(t) repo, cleanup := repository.TestRepository(t)
defer cleanup() defer cleanup()
lock1, err := restic.NewLock(repo) lock1, err := restic.NewLock(repo)
@ -48,7 +49,7 @@ func TestMultipleLock(t *testing.T) {
} }
func TestLockExclusive(t *testing.T) { func TestLockExclusive(t *testing.T) {
repo, cleanup := SetupRepo(t) repo, cleanup := repository.TestRepository(t)
defer cleanup() defer cleanup()
elock, err := restic.NewExclusiveLock(repo) elock, err := restic.NewExclusiveLock(repo)
@ -57,7 +58,7 @@ func TestLockExclusive(t *testing.T) {
} }
func TestLockOnExclusiveLockedRepo(t *testing.T) { func TestLockOnExclusiveLockedRepo(t *testing.T) {
repo, cleanup := SetupRepo(t) repo, cleanup := repository.TestRepository(t)
defer cleanup() defer cleanup()
elock, err := restic.NewExclusiveLock(repo) elock, err := restic.NewExclusiveLock(repo)
@ -74,7 +75,7 @@ func TestLockOnExclusiveLockedRepo(t *testing.T) {
} }
func TestExclusiveLockOnLockedRepo(t *testing.T) { func TestExclusiveLockOnLockedRepo(t *testing.T) {
repo, cleanup := SetupRepo(t) repo, cleanup := repository.TestRepository(t)
defer cleanup() defer cleanup()
elock, err := restic.NewLock(repo) 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) { func TestLockWithStaleLock(t *testing.T) {
repo, cleanup := SetupRepo(t) repo, cleanup := repository.TestRepository(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())
@ -193,7 +194,7 @@ func TestLockWithStaleLock(t *testing.T) {
} }
func TestRemoveAllLocks(t *testing.T) { func TestRemoveAllLocks(t *testing.T) {
repo, cleanup := SetupRepo(t) repo, cleanup := repository.TestRepository(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())
@ -216,7 +217,7 @@ func TestRemoveAllLocks(t *testing.T) {
} }
func TestLockRefresh(t *testing.T) { func TestLockRefresh(t *testing.T) {
repo, cleanup := SetupRepo(t) repo, cleanup := repository.TestRepository(t)
defer cleanup() defer cleanup()
lock, err := restic.NewLock(repo) lock, err := restic.NewLock(repo)

View File

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

View File

@ -2,14 +2,7 @@ package test_helper
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath"
"testing"
"restic"
"restic/backend/local"
"restic/repository"
) )
var ( var (
@ -47,40 +40,3 @@ func getBoolVar(name string, defaultValue bool) bool {
return defaultValue 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" "testing"
"restic" "restic"
"restic/repository"
. "restic/test" . "restic/test"
) )
@ -92,7 +93,7 @@ func TestNodeComparison(t *testing.T) {
} }
func TestLoadTree(t *testing.T) { func TestLoadTree(t *testing.T) {
repo, cleanup := SetupRepo(t) repo, cleanup := repository.TestRepository(t)
defer cleanup() defer cleanup()
// save tree // save tree

View File

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