Merge pull request #3248 from MichaelEischer/backend-cleanups
Backend code and test cleanups
This commit is contained in:
commit
f647614e24
2 changed files with 6 additions and 4 deletions
|
@ -81,14 +81,14 @@ func (be *MemoryBackend) Save(ctx context.Context, h restic.Handle, rd restic.Re
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
be.data[h] = buf
|
|
||||||
debug.Log("saved %v bytes at %v", len(buf), h)
|
|
||||||
|
|
||||||
// sanity check
|
// sanity check
|
||||||
if int64(len(buf)) != rd.Length() {
|
if int64(len(buf)) != rd.Length() {
|
||||||
return errors.Errorf("wrote %d bytes instead of the expected %d bytes", len(buf), rd.Length())
|
return errors.Errorf("wrote %d bytes instead of the expected %d bytes", len(buf), rd.Length())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
be.data[h] = buf
|
||||||
|
debug.Log("saved %v bytes at %v", len(buf), h)
|
||||||
|
|
||||||
return ctx.Err()
|
return ctx.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -577,13 +577,15 @@ func (s *Suite) TestSaveError(t *testing.T) {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
length := rand.Intn(1<<23) + 200000
|
length := rand.Intn(1<<23) + 200000
|
||||||
data := test.Random(23, length)
|
data := test.Random(24, length)
|
||||||
var id restic.ID
|
var id restic.ID
|
||||||
copy(id[:], data)
|
copy(id[:], data)
|
||||||
|
|
||||||
// test that incomplete uploads fail
|
// test that incomplete uploads fail
|
||||||
h := restic.Handle{Type: restic.PackFile, Name: id.String()}
|
h := restic.Handle{Type: restic.PackFile, Name: id.String()}
|
||||||
err := b.Save(context.TODO(), h, &incompleteByteReader{ByteReader: *restic.NewByteReader(data)})
|
err := b.Save(context.TODO(), h, &incompleteByteReader{ByteReader: *restic.NewByteReader(data)})
|
||||||
|
// try to delete possible leftovers
|
||||||
|
_ = s.delayedRemove(t, b, h)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("incomplete upload did not fail")
|
t.Fatal("incomplete upload did not fail")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue