mirror of
https://github.com/octoleo/restic.git
synced 2024-11-30 00:33:57 +00:00
a37ed45534
LoadAll() should not pass on io.ErrUnexpectedEOF, since the occurrence of this error is normal.
92 lines
2.0 KiB
Go
92 lines
2.0 KiB
Go
package backend_test
|
|
|
|
import (
|
|
"bytes"
|
|
"math/rand"
|
|
"testing"
|
|
|
|
"github.com/restic/restic/backend"
|
|
"github.com/restic/restic/backend/mem"
|
|
. "github.com/restic/restic/test"
|
|
)
|
|
|
|
const KiB = 1 << 10
|
|
const MiB = 1 << 20
|
|
|
|
func TestLoadAll(t *testing.T) {
|
|
b := mem.New()
|
|
|
|
for i := 0; i < 20; i++ {
|
|
data := Random(23+i, rand.Intn(MiB)+500*KiB)
|
|
|
|
id := backend.Hash(data)
|
|
err := b.Save(backend.Handle{Name: id.String(), Type: backend.Data}, data)
|
|
OK(t, err)
|
|
|
|
buf, err := backend.LoadAll(b, backend.Handle{Type: backend.Data, Name: id.String()}, nil)
|
|
OK(t, err)
|
|
|
|
if len(buf) != len(data) {
|
|
t.Errorf("length of returned buffer does not match, want %d, got %d", len(data), len(buf))
|
|
continue
|
|
}
|
|
|
|
if !bytes.Equal(buf, data) {
|
|
t.Errorf("wrong data returned")
|
|
continue
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestLoadSmallBuffer(t *testing.T) {
|
|
b := mem.New()
|
|
|
|
for i := 0; i < 20; i++ {
|
|
data := Random(23+i, rand.Intn(MiB)+500*KiB)
|
|
|
|
id := backend.Hash(data)
|
|
err := b.Save(backend.Handle{Name: id.String(), Type: backend.Data}, data)
|
|
OK(t, err)
|
|
|
|
buf := make([]byte, len(data)-23)
|
|
buf, err = backend.LoadAll(b, backend.Handle{Type: backend.Data, Name: id.String()}, buf)
|
|
OK(t, err)
|
|
|
|
if len(buf) != len(data) {
|
|
t.Errorf("length of returned buffer does not match, want %d, got %d", len(data), len(buf))
|
|
continue
|
|
}
|
|
|
|
if !bytes.Equal(buf, data) {
|
|
t.Errorf("wrong data returned")
|
|
continue
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestLoadLargeBuffer(t *testing.T) {
|
|
b := mem.New()
|
|
|
|
for i := 0; i < 20; i++ {
|
|
data := Random(23+i, rand.Intn(MiB)+500*KiB)
|
|
|
|
id := backend.Hash(data)
|
|
err := b.Save(backend.Handle{Name: id.String(), Type: backend.Data}, data)
|
|
OK(t, err)
|
|
|
|
buf := make([]byte, len(data)+100)
|
|
buf, err = backend.LoadAll(b, backend.Handle{Type: backend.Data, Name: id.String()}, buf)
|
|
OK(t, err)
|
|
|
|
if len(buf) != len(data) {
|
|
t.Errorf("length of returned buffer does not match, want %d, got %d", len(data), len(buf))
|
|
continue
|
|
}
|
|
|
|
if !bytes.Equal(buf, data) {
|
|
t.Errorf("wrong data returned")
|
|
continue
|
|
}
|
|
}
|
|
}
|