tests: Standardize use of SetupRepo/Teardown
This commit is contained in:
parent
d9a8dcfd67
commit
189a33730a
7 changed files with 65 additions and 51 deletions
|
@ -45,27 +45,38 @@ func getBoolVar(name string, defaultValue bool) bool {
|
|||
return defaultValue
|
||||
}
|
||||
|
||||
func SetupRepo(t testing.TB) *repository.Repository {
|
||||
func SetupRepo() *repository.Repository {
|
||||
tempdir, err := ioutil.TempDir(TestTempDir, "restic-test-")
|
||||
OK(t, err)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// create repository below temp dir
|
||||
b, err := local.Create(filepath.Join(tempdir, "repo"))
|
||||
OK(t, err)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
repo := repository.New(b)
|
||||
OK(t, repo.Init(TestPassword))
|
||||
err = repo.Init(TestPassword)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return repo
|
||||
}
|
||||
|
||||
func TeardownRepo(t testing.TB, repo *repository.Repository) {
|
||||
func TeardownRepo(repo *repository.Repository) {
|
||||
if !TestCleanup {
|
||||
l := repo.Backend().(*local.Local)
|
||||
t.Logf("leaving local backend at %s\n", l.Location())
|
||||
fmt.Printf("leaving local backend at %s\n", l.Location())
|
||||
return
|
||||
}
|
||||
|
||||
OK(t, repo.Delete())
|
||||
err := repo.Delete()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func SnapshotDir(t testing.TB, repo *repository.Repository, path string, parent backend.ID) *restic.Snapshot {
|
||||
|
@ -74,3 +85,9 @@ func SnapshotDir(t testing.TB, repo *repository.Repository, path string, parent
|
|||
OK(t, err)
|
||||
return sn
|
||||
}
|
||||
|
||||
func WithRepo(t testing.TB, f func(*repository.Repository)) {
|
||||
repo := SetupRepo()
|
||||
f(repo)
|
||||
TeardownRepo(repo)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue