mirror of
https://github.com/restic/restic.git
synced 2025-12-03 22:01:46 +00:00
backend: remove Test method
The Test method was only used in exactly one place, namely when trying to create a new repository it was used to check whether a config file already exists. Use a combination of Stat() and IsNotExist() instead.
This commit is contained in:
@@ -27,6 +27,15 @@ func seedRand(t testing.TB) {
|
||||
t.Logf("rand initialized with seed %d", seed)
|
||||
}
|
||||
|
||||
func beTest(ctx context.Context, be restic.Backend, h restic.Handle) (bool, error) {
|
||||
_, err := be.Stat(ctx, h)
|
||||
if err != nil && be.IsNotExist(err) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return err == nil, err
|
||||
}
|
||||
|
||||
// TestCreateWithConfig tests that creating a backend in a location which already
|
||||
// has a config file fails.
|
||||
func (s *Suite) TestCreateWithConfig(t *testing.T) {
|
||||
@@ -35,7 +44,7 @@ func (s *Suite) TestCreateWithConfig(t *testing.T) {
|
||||
|
||||
// remove a config if present
|
||||
cfgHandle := restic.Handle{Type: restic.ConfigFile}
|
||||
cfgPresent, err := b.Test(context.TODO(), cfgHandle)
|
||||
cfgPresent, err := beTest(context.TODO(), b, cfgHandle)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to test for config: %+v", err)
|
||||
}
|
||||
@@ -642,7 +651,7 @@ func (s *Suite) TestSaveWrongHash(t *testing.T) {
|
||||
// test that upload with hash mismatch fails
|
||||
h := restic.Handle{Type: restic.PackFile, Name: id.String()}
|
||||
err := b.Save(context.TODO(), h, &wrongByteReader{ByteReader: *restic.NewByteReader(data, b.Hasher())})
|
||||
exists, err2 := b.Test(context.TODO(), h)
|
||||
exists, err2 := beTest(context.TODO(), b, h)
|
||||
if err2 != nil {
|
||||
t.Fatal(err2)
|
||||
}
|
||||
@@ -702,7 +711,7 @@ func (s *Suite) delayedRemove(t testing.TB, be restic.Backend, handles ...restic
|
||||
var found bool
|
||||
var err error
|
||||
for time.Since(start) <= s.WaitForDelayedRemoval {
|
||||
found, err = be.Test(context.TODO(), h)
|
||||
found, err = beTest(context.TODO(), be, h)
|
||||
if s.ErrorHandler != nil {
|
||||
err = s.ErrorHandler(t, be, err)
|
||||
}
|
||||
@@ -764,7 +773,7 @@ func (s *Suite) TestBackend(t *testing.T) {
|
||||
|
||||
// test if blob is already in repository
|
||||
h := restic.Handle{Type: tpe, Name: id.String()}
|
||||
ret, err := b.Test(context.TODO(), h)
|
||||
ret, err := beTest(context.TODO(), b, h)
|
||||
test.OK(t, err)
|
||||
test.Assert(t, !ret, "blob was found to exist before creating")
|
||||
|
||||
@@ -777,7 +786,7 @@ func (s *Suite) TestBackend(t *testing.T) {
|
||||
test.Assert(t, err != nil, "blob could be read before creation")
|
||||
|
||||
// try to get string out, should fail
|
||||
ret, err = b.Test(context.TODO(), h)
|
||||
ret, err = beTest(context.TODO(), b, h)
|
||||
test.OK(t, err)
|
||||
test.Assert(t, !ret, "id %q was found (but should not have)", ts.id)
|
||||
}
|
||||
@@ -818,7 +827,7 @@ func (s *Suite) TestBackend(t *testing.T) {
|
||||
test.OK(t, err)
|
||||
|
||||
// test that the blob is gone
|
||||
ok, err := b.Test(context.TODO(), h)
|
||||
ok, err := beTest(context.TODO(), b, h)
|
||||
test.OK(t, err)
|
||||
test.Assert(t, !ok, "removed blob still present")
|
||||
|
||||
@@ -854,9 +863,9 @@ func (s *Suite) TestBackend(t *testing.T) {
|
||||
|
||||
h := restic.Handle{Type: tpe, Name: id.String()}
|
||||
|
||||
found, err := b.Test(context.TODO(), h)
|
||||
found, err := beTest(context.TODO(), b, h)
|
||||
test.OK(t, err)
|
||||
test.Assert(t, found, fmt.Sprintf("id %q not found", id))
|
||||
test.Assert(t, found, fmt.Sprintf("id %v/%q not found", tpe, id))
|
||||
|
||||
handles = append(handles, h)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user