From 876c5fe9fc4a2a727607860401f1eb85b89b0faf Mon Sep 17 00:00:00 2001 From: bstrausser Date: Fri, 8 Mar 2024 20:34:20 -0500 Subject: [PATCH 1/2] Fix sparse file test offset/length --- sparse-file_test.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sparse-file_test.go b/sparse-file_test.go index fa77e2c..2ce65f3 100644 --- a/sparse-file_test.go +++ b/sparse-file_test.go @@ -79,18 +79,19 @@ func TestSparseFileRead(t *testing.T) { require.NoError(t, err) defer h.Close() - // Read a few randome ranges and compare to the expected blob content - for i := 0; i < 10; i++ { - start := rand.Intn(int(index.Length())) + // Read a few random ranges and compare to the expected blob content + for i := 0; i < 1000; i++ { length := rand.Intn(int(index.Index.ChunkSizeMax)) + offset := rand.Intn(int(index.Length()) - length) + fromSparse := make([]byte, length) fromBlob := make([]byte, length) - _, err := h.ReadAt(fromSparse, int64(start)) + _, err := h.ReadAt(fromSparse, int64(offset)) require.NoError(t, err) - _, err = bytes.NewReader(b).ReadAt(fromBlob, int64(start)) + _, err = bytes.NewReader(b).ReadAt(fromBlob, int64(offset)) require.NoError(t, err) require.Equal(t, fromBlob, fromSparse) From ad1dd2b64ff5fc5bd9bdced9dd685a6fb9d6b5e1 Mon Sep 17 00:00:00 2001 From: bstrausser Date: Sun, 10 Mar 2024 12:49:42 -0400 Subject: [PATCH 2/2] Fix off-by-one error --- sparse-file_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sparse-file_test.go b/sparse-file_test.go index 2ce65f3..9eac7c0 100644 --- a/sparse-file_test.go +++ b/sparse-file_test.go @@ -82,7 +82,7 @@ func TestSparseFileRead(t *testing.T) { // Read a few random ranges and compare to the expected blob content for i := 0; i < 1000; i++ { length := rand.Intn(int(index.Index.ChunkSizeMax)) - offset := rand.Intn(int(index.Length()) - length) + offset := rand.Intn(int(index.Length()) - length -1) fromSparse := make([]byte, length)