mirror of
https://github.com/octoleo/restic.git
synced 2024-11-21 20:35:12 +00:00
repository: make repo.Options configurable for test repos
This commit is contained in:
parent
29e1caf825
commit
0ea62b5ac6
@ -1879,7 +1879,7 @@ func TestArchiverContextCanceled(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Ensure that the archiver itself reports the canceled context and not just the backend
|
// Ensure that the archiver itself reports the canceled context and not just the backend
|
||||||
repo := repository.TestRepositoryWithBackend(t, &noCancelBackend{mem.New()}, 0)
|
repo := repository.TestRepositoryWithBackend(t, &noCancelBackend{mem.New()}, 0, repository.Options{})
|
||||||
|
|
||||||
back := restictest.Chdir(t, tempdir)
|
back := restictest.Chdir(t, tempdir)
|
||||||
defer back()
|
defer back()
|
||||||
|
@ -69,7 +69,7 @@ func TestUpgradeRepoV2Failure(t *testing.T) {
|
|||||||
Backend: be,
|
Backend: be,
|
||||||
}
|
}
|
||||||
|
|
||||||
repo := repository.TestRepositoryWithBackend(t, be, 1)
|
repo := repository.TestRepositoryWithBackend(t, be, 1, repository.Options{})
|
||||||
if repo.Config().Version != 1 {
|
if repo.Config().Version != 1 {
|
||||||
t.Fatal("test repo has wrong version")
|
t.Fatal("test repo has wrong version")
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/restic/restic/internal/backend/mem"
|
|
||||||
"github.com/restic/restic/internal/restic"
|
"github.com/restic/restic/internal/restic"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
)
|
)
|
||||||
@ -19,7 +18,7 @@ func FuzzSaveLoadBlob(f *testing.F) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
id := restic.Hash(blob)
|
id := restic.Hash(blob)
|
||||||
repo := TestRepositoryWithBackend(t, mem.New(), 2)
|
repo := TestRepositoryWithVersion(t, 2)
|
||||||
|
|
||||||
var wg errgroup.Group
|
var wg errgroup.Group
|
||||||
repo.StartPackUploader(context.TODO(), &wg)
|
repo.StartPackUploader(context.TODO(), &wg)
|
||||||
|
@ -43,7 +43,7 @@ const TestChunkerPol = chunker.Pol(0x3DA3358B4DC173)
|
|||||||
// TestRepositoryWithBackend returns a repository initialized with a test
|
// TestRepositoryWithBackend returns a repository initialized with a test
|
||||||
// password. If be is nil, an in-memory backend is used. A constant polynomial
|
// password. If be is nil, an in-memory backend is used. A constant polynomial
|
||||||
// is used for the chunker and low-security test parameters.
|
// is used for the chunker and low-security test parameters.
|
||||||
func TestRepositoryWithBackend(t testing.TB, be restic.Backend, version uint) restic.Repository {
|
func TestRepositoryWithBackend(t testing.TB, be restic.Backend, version uint, opts Options) restic.Repository {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
TestUseLowSecurityKDFParameters(t)
|
TestUseLowSecurityKDFParameters(t)
|
||||||
restic.TestDisableCheckPolynomial(t)
|
restic.TestDisableCheckPolynomial(t)
|
||||||
@ -52,7 +52,7 @@ func TestRepositoryWithBackend(t testing.TB, be restic.Backend, version uint) re
|
|||||||
be = TestBackend(t)
|
be = TestBackend(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
repo, err := New(be, Options{})
|
repo, err := New(be, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("TestRepository(): new repo failed: %v", err)
|
t.Fatalf("TestRepository(): new repo failed: %v", err)
|
||||||
}
|
}
|
||||||
@ -78,6 +78,7 @@ func TestRepository(t testing.TB) restic.Repository {
|
|||||||
func TestRepositoryWithVersion(t testing.TB, version uint) restic.Repository {
|
func TestRepositoryWithVersion(t testing.TB, version uint) restic.Repository {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
dir := os.Getenv("RESTIC_TEST_REPO")
|
dir := os.Getenv("RESTIC_TEST_REPO")
|
||||||
|
opts := Options{}
|
||||||
if dir != "" {
|
if dir != "" {
|
||||||
_, err := os.Stat(dir)
|
_, err := os.Stat(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -85,7 +86,7 @@ func TestRepositoryWithVersion(t testing.TB, version uint) restic.Repository {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error creating local backend at %v: %v", dir, err)
|
t.Fatalf("error creating local backend at %v: %v", dir, err)
|
||||||
}
|
}
|
||||||
return TestRepositoryWithBackend(t, be, version)
|
return TestRepositoryWithBackend(t, be, version, opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -93,7 +94,7 @@ func TestRepositoryWithVersion(t testing.TB, version uint) restic.Repository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return TestRepositoryWithBackend(t, nil, version)
|
return TestRepositoryWithBackend(t, nil, version, opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestOpenLocal opens a local repository.
|
// TestOpenLocal opens a local repository.
|
||||||
|
@ -65,7 +65,7 @@ func (be *failLockLoadingBackend) Load(ctx context.Context, h restic.Handle, len
|
|||||||
|
|
||||||
func TestMultipleLockFailure(t *testing.T) {
|
func TestMultipleLockFailure(t *testing.T) {
|
||||||
be := &failLockLoadingBackend{Backend: mem.New()}
|
be := &failLockLoadingBackend{Backend: mem.New()}
|
||||||
repo := repository.TestRepositoryWithBackend(t, be, 0)
|
repo := repository.TestRepositoryWithBackend(t, be, 0, repository.Options{})
|
||||||
restic.TestSetLockTimeout(t, 5*time.Millisecond)
|
restic.TestSetLockTimeout(t, 5*time.Millisecond)
|
||||||
|
|
||||||
lock1, err := restic.NewLock(context.TODO(), repo)
|
lock1, err := restic.NewLock(context.TODO(), repo)
|
||||||
|
Loading…
Reference in New Issue
Block a user