From 9f7cd69f1353d4c1e39ab471989df526c5bf1785 Mon Sep 17 00:00:00 2001
From: greatroar <@>
Date: Wed, 29 Apr 2020 10:57:01 +0200
Subject: [PATCH] Move Index.FindBlob to tests

---
 internal/index/index.go      | 30 ------------------------------
 internal/index/index_test.go | 32 +++++++++++++++++++++++++++-----
 2 files changed, 27 insertions(+), 35 deletions(-)

diff --git a/internal/index/index.go b/internal/index/index.go
index 6c6294b21..75a6a53fc 100644
--- a/internal/index/index.go
+++ b/internal/index/index.go
@@ -312,36 +312,6 @@ func (idx *Index) PacksForBlobs(blobs restic.BlobSet) (packs restic.IDSet) {
 	return packs
 }
 
-// Location describes the location of a blob in a pack.
-type Location struct {
-	PackID restic.ID
-	restic.Blob
-}
-
-// ErrBlobNotFound is return by FindBlob when the blob could not be found in
-// the index.
-var ErrBlobNotFound = errors.New("blob not found in index")
-
-// FindBlob returns a list of packs and positions the blob can be found in.
-func (idx *Index) FindBlob(h restic.BlobHandle) (result []Location, err error) {
-	for id, p := range idx.Packs {
-		for _, entry := range p.Entries {
-			if entry.ID.Equal(h.ID) && entry.Type == h.Type {
-				result = append(result, Location{
-					PackID: id,
-					Blob:   entry,
-				})
-			}
-		}
-	}
-
-	if len(result) == 0 {
-		return nil, ErrBlobNotFound
-	}
-
-	return result, nil
-}
-
 const maxEntries = 3000
 
 // Saver saves structures as JSON.
diff --git a/internal/index/index_test.go b/internal/index/index_test.go
index 43198cf68..ca9a9f899 100644
--- a/internal/index/index_test.go
+++ b/internal/index/index_test.go
@@ -363,6 +363,28 @@ func TestIndexSave(t *testing.T) {
 	}
 }
 
+// Location describes the location of a blob in a pack.
+type location struct {
+	PackID restic.ID
+	restic.Blob
+}
+
+// FindBlob returns a list of packs and positions the blob can be found in.
+func (idx *Index) findBlob(h restic.BlobHandle) (result []location) {
+	for id, p := range idx.Packs {
+		for _, entry := range p.Entries {
+			if entry.ID.Equal(h.ID) && entry.Type == h.Type {
+				result = append(result, location{
+					PackID: id,
+					Blob:   entry,
+				})
+			}
+		}
+	}
+
+	return result
+}
+
 func TestIndexAddRemovePack(t *testing.T) {
 	repo, cleanup := createFilledRepo(t, 3, 0)
 	defer cleanup()
@@ -393,8 +415,8 @@ func TestIndexAddRemovePack(t *testing.T) {
 
 	for _, blob := range blobs {
 		h := restic.BlobHandle{ID: blob.ID, Type: blob.Type}
-		_, err := idx.FindBlob(h)
-		if err == nil {
+		locs := idx.findBlob(h)
+		if len(locs) != 0 {
 			t.Errorf("removed blob %v found in index", h)
 		}
 	}
@@ -447,9 +469,9 @@ func TestIndexLoadDocReference(t *testing.T) {
 	idx := loadIndex(t, repo)
 
 	blobID := restic.TestParseID("d3dc577b4ffd38cc4b32122cabf8655a0223ed22edfd93b353dc0c3f2b0fdf66")
-	locs, err := idx.FindBlob(restic.BlobHandle{ID: blobID, Type: restic.DataBlob})
-	if err != nil {
-		t.Errorf("FindBlob() returned error %v", err)
+	locs := idx.findBlob(restic.BlobHandle{ID: blobID, Type: restic.DataBlob})
+	if len(locs) == 0 {
+		t.Error("blob not found in index")
 	}
 
 	if len(locs) != 1 {