diff --git a/src/restic/archiver/archive_reader_test.go b/src/restic/archiver/archive_reader_test.go index e7e88d6cd..f9417cb51 100644 --- a/src/restic/archiver/archive_reader_test.go +++ b/src/restic/archiver/archive_reader_test.go @@ -7,17 +7,15 @@ import ( "restic" "restic/repository" "testing" - - "github.com/restic/chunker" ) -func loadBlob(t *testing.T, repo restic.Repository, id restic.ID, buf []byte) []byte { +func loadBlob(t *testing.T, repo restic.Repository, id restic.ID, buf []byte) int { n, err := repo.LoadDataBlob(id, buf) if err != nil { t.Fatalf("LoadBlob(%v) returned error %v", id, err) } - return buf[:n] + return n } func checkSavedFile(t *testing.T, repo restic.Repository, treeID restic.ID, name string, rd io.Reader) { @@ -40,12 +38,19 @@ func checkSavedFile(t *testing.T, repo restic.Repository, treeID restic.ID, name } // check blobs - buf := make([]byte, chunker.MaxSize) - buf2 := make([]byte, chunker.MaxSize) for i, id := range node.Content { - buf = loadBlob(t, repo, id, buf) + size, err := repo.LookupBlobSize(id, restic.DataBlob) + if err != nil { + t.Fatal(err) + } - buf2 = buf2[:len(buf)] + buf := make([]byte, int(size)) + n := loadBlob(t, repo, id, buf) + if n != len(buf) { + t.Errorf("wrong number of bytes read, want %d, got %d", len(buf), n) + } + + buf2 := make([]byte, int(size)) _, err = io.ReadFull(rd, buf2) if err != nil { t.Fatal(err) diff --git a/src/restic/fuse/file_test.go b/src/restic/fuse/file_test.go index 0101cadc9..1013a07b5 100644 --- a/src/restic/fuse/file_test.go +++ b/src/restic/fuse/file_test.go @@ -40,7 +40,7 @@ func (m *MockRepo) LoadDataBlob(id restic.ID, buf []byte) (int, error) { return 0, err } - if uint(cap(buf)) < size { + if uint(len(buf)) < size { return 0, errors.New("buffer too small") } @@ -81,7 +81,7 @@ func genTestContent() map[restic.ID][]byte { const maxBufSize = 20 * 1024 * 1024 -func testRead(t *testing.T, f *file, offset, length int, data []byte) []byte { +func testRead(t *testing.T, f *file, offset, length int, data []byte) { ctx := MockContext{} req := &fuse.ReadRequest{ @@ -92,8 +92,6 @@ func testRead(t *testing.T, f *file, offset, length int, data []byte) []byte { Data: make([]byte, length), } OK(t, f.Read(ctx, req, resp)) - - return resp.Data } var offsetReadsTests = []struct { @@ -135,8 +133,9 @@ func TestFuseFile(t *testing.T) { for i, test := range offsetReadsTests { b := memfile[test.offset : test.offset+test.length] - res := testRead(t, f, test.offset, test.length, b) - if !bytes.Equal(b, res) { + buf := make([]byte, test.length) + testRead(t, f, test.offset, test.length, buf) + if !bytes.Equal(b, buf) { t.Errorf("test %d failed, wrong data returned", i) } } @@ -150,8 +149,9 @@ func TestFuseFile(t *testing.T) { } b := memfile[offset : offset+length] - res := testRead(t, f, offset, length, b) - if !bytes.Equal(b, res) { + buf := make([]byte, length) + testRead(t, f, offset, length, buf) + if !bytes.Equal(b, buf) { t.Errorf("test %d failed (offset %d, length %d), wrong data returned", i, offset, length) } }