2016-08-07 15:19:00 +00:00
|
|
|
package index
|
|
|
|
|
|
|
|
import (
|
2017-06-05 21:56:59 +00:00
|
|
|
"context"
|
2018-10-28 13:02:31 +00:00
|
|
|
"sync"
|
2016-08-07 15:19:00 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
2017-07-23 12:21:03 +00:00
|
|
|
|
|
|
|
"github.com/restic/restic/internal/checker"
|
2018-10-28 12:16:36 +00:00
|
|
|
"github.com/restic/restic/internal/errors"
|
2017-07-23 12:21:03 +00:00
|
|
|
"github.com/restic/restic/internal/repository"
|
2017-07-24 15:42:25 +00:00
|
|
|
"github.com/restic/restic/internal/restic"
|
2017-07-23 12:21:03 +00:00
|
|
|
"github.com/restic/restic/internal/test"
|
2016-08-07 15:19:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
snapshotTime = time.Unix(1470492820, 207401672)
|
|
|
|
depth = 3
|
|
|
|
)
|
|
|
|
|
2016-09-03 11:34:04 +00:00
|
|
|
func createFilledRepo(t testing.TB, snapshots int, dup float32) (restic.Repository, func()) {
|
2016-08-07 15:19:00 +00:00
|
|
|
repo, cleanup := repository.TestRepository(t)
|
|
|
|
|
|
|
|
for i := 0; i < 3; i++ {
|
2016-08-07 19:56:06 +00:00
|
|
|
restic.TestCreateSnapshot(t, repo, snapshotTime.Add(time.Duration(i)*time.Second), depth, dup)
|
2016-08-07 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return repo, cleanup
|
|
|
|
}
|
|
|
|
|
2016-09-03 11:34:04 +00:00
|
|
|
func validateIndex(t testing.TB, repo restic.Repository, idx *Index) {
|
2018-01-21 16:25:36 +00:00
|
|
|
err := repo.List(context.TODO(), restic.DataFile, func(id restic.ID, size int64) error {
|
2017-01-22 21:09:56 +00:00
|
|
|
p, ok := idx.Packs[id]
|
|
|
|
if !ok {
|
2016-08-07 16:45:25 +00:00
|
|
|
t.Errorf("pack %v missing from index", id.Str())
|
|
|
|
}
|
2017-01-22 21:09:56 +00:00
|
|
|
|
|
|
|
if !p.ID.Equal(id) {
|
|
|
|
t.Errorf("pack %v has invalid ID: want %v, got %v", id.Str(), id, p.ID)
|
|
|
|
}
|
2018-01-21 16:25:36 +00:00
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
2016-08-07 16:45:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-07 15:19:00 +00:00
|
|
|
func TestIndexNew(t *testing.T) {
|
2016-08-07 19:56:06 +00:00
|
|
|
repo, cleanup := createFilledRepo(t, 3, 0)
|
2016-08-07 15:19:00 +00:00
|
|
|
defer cleanup()
|
|
|
|
|
2018-10-28 12:16:36 +00:00
|
|
|
idx, invalid, err := New(context.TODO(), repo, restic.NewIDSet(), nil)
|
2016-08-07 15:19:00 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("New() returned error %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if idx == nil {
|
|
|
|
t.Fatalf("New() returned nil index")
|
|
|
|
}
|
2016-08-07 16:45:25 +00:00
|
|
|
|
2018-10-28 12:16:36 +00:00
|
|
|
if len(invalid) > 0 {
|
|
|
|
t.Fatalf("New() returned invalid files: %v", invalid)
|
|
|
|
}
|
|
|
|
|
2016-08-07 16:45:25 +00:00
|
|
|
validateIndex(t, repo, idx)
|
2016-08-07 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
2018-10-28 13:02:31 +00:00
|
|
|
type ErrorRepo struct {
|
2018-10-28 12:16:36 +00:00
|
|
|
restic.Repository
|
2018-10-28 13:02:31 +00:00
|
|
|
MaxListFiles int
|
|
|
|
|
|
|
|
MaxPacks int
|
|
|
|
MaxPacksMutex sync.Mutex
|
2018-10-28 12:16:36 +00:00
|
|
|
}
|
|
|
|
|
2018-10-28 13:02:31 +00:00
|
|
|
// List returns an error after repo.MaxListFiles files.
|
|
|
|
func (repo *ErrorRepo) List(ctx context.Context, t restic.FileType, fn func(restic.ID, int64) error) error {
|
|
|
|
if repo.MaxListFiles == 0 {
|
2018-10-28 12:16:36 +00:00
|
|
|
return errors.New("test error, max is zero")
|
|
|
|
}
|
|
|
|
|
2018-10-28 13:02:31 +00:00
|
|
|
max := repo.MaxListFiles
|
2018-10-28 12:16:36 +00:00
|
|
|
return repo.Repository.List(ctx, t, func(id restic.ID, size int64) error {
|
|
|
|
if max == 0 {
|
|
|
|
return errors.New("test error, max reached zero")
|
|
|
|
}
|
|
|
|
|
|
|
|
max--
|
|
|
|
return fn(id, size)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-10-28 13:02:31 +00:00
|
|
|
// ListPack returns an error after repo.MaxPacks files.
|
|
|
|
func (repo *ErrorRepo) ListPack(ctx context.Context, id restic.ID, size int64) ([]restic.Blob, int64, error) {
|
|
|
|
repo.MaxPacksMutex.Lock()
|
|
|
|
max := repo.MaxPacks
|
|
|
|
if max > 0 {
|
|
|
|
repo.MaxPacks--
|
|
|
|
}
|
|
|
|
repo.MaxPacksMutex.Unlock()
|
|
|
|
|
|
|
|
if max == 0 {
|
|
|
|
return nil, 0, errors.New("test list pack error")
|
|
|
|
}
|
|
|
|
|
|
|
|
return repo.Repository.ListPack(ctx, id, size)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIndexNewListErrors(t *testing.T) {
|
|
|
|
repo, cleanup := createFilledRepo(t, 3, 0)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
for _, max := range []int{0, 3, 5} {
|
|
|
|
errRepo := &ErrorRepo{
|
|
|
|
Repository: repo,
|
|
|
|
MaxListFiles: max,
|
|
|
|
}
|
|
|
|
idx, invalid, err := New(context.TODO(), errRepo, restic.NewIDSet(), nil)
|
|
|
|
if err == nil {
|
|
|
|
t.Errorf("expected error not found, got nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
if idx != nil {
|
|
|
|
t.Errorf("expected nil index, got %v", idx)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(invalid) != 0 {
|
|
|
|
t.Errorf("expected empty invalid list, got %v", invalid)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIndexNewPackErrors(t *testing.T) {
|
2018-10-28 12:16:36 +00:00
|
|
|
repo, cleanup := createFilledRepo(t, 3, 0)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
for _, max := range []int{0, 3, 5} {
|
2018-10-28 13:02:31 +00:00
|
|
|
errRepo := &ErrorRepo{
|
2018-10-28 12:16:36 +00:00
|
|
|
Repository: repo,
|
2018-10-28 13:02:31 +00:00
|
|
|
MaxPacks: max,
|
2018-10-28 12:16:36 +00:00
|
|
|
}
|
|
|
|
idx, invalid, err := New(context.TODO(), errRepo, restic.NewIDSet(), nil)
|
|
|
|
if err == nil {
|
|
|
|
t.Errorf("expected error not found, got nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
if idx != nil {
|
|
|
|
t.Errorf("expected nil index, got %v", idx)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(invalid) != 0 {
|
|
|
|
t.Errorf("expected empty invalid list, got %v", invalid)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-07 15:19:00 +00:00
|
|
|
func TestIndexLoad(t *testing.T) {
|
2016-08-07 19:56:06 +00:00
|
|
|
repo, cleanup := createFilledRepo(t, 3, 0)
|
2016-08-07 15:19:00 +00:00
|
|
|
defer cleanup()
|
|
|
|
|
2017-06-05 21:56:59 +00:00
|
|
|
loadIdx, err := Load(context.TODO(), repo, nil)
|
2016-08-07 15:19:00 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Load() returned error %v", err)
|
|
|
|
}
|
|
|
|
|
2016-08-07 16:45:25 +00:00
|
|
|
if loadIdx == nil {
|
2016-08-07 15:19:00 +00:00
|
|
|
t.Fatalf("Load() returned nil index")
|
|
|
|
}
|
2016-08-07 16:45:25 +00:00
|
|
|
|
|
|
|
validateIndex(t, repo, loadIdx)
|
|
|
|
|
2017-06-15 13:03:05 +00:00
|
|
|
newIdx, _, err := New(context.TODO(), repo, restic.NewIDSet(), nil)
|
2016-08-07 16:45:25 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("New() returned error %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(loadIdx.Packs) != len(newIdx.Packs) {
|
|
|
|
t.Errorf("number of packs does not match: want %v, got %v",
|
|
|
|
len(loadIdx.Packs), len(newIdx.Packs))
|
|
|
|
}
|
|
|
|
|
|
|
|
validateIndex(t, repo, newIdx)
|
|
|
|
|
|
|
|
for packID, packNew := range newIdx.Packs {
|
|
|
|
packLoad, ok := loadIdx.Packs[packID]
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
t.Errorf("loaded index does not list pack %v", packID.Str())
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(packNew.Entries) != len(packLoad.Entries) {
|
|
|
|
t.Errorf(" number of entries in pack %v does not match: %d != %d\n %v\n %v",
|
|
|
|
packID.Str(), len(packNew.Entries), len(packLoad.Entries),
|
|
|
|
packNew.Entries, packLoad.Entries)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, entryNew := range packNew.Entries {
|
|
|
|
found := false
|
|
|
|
for _, entryLoad := range packLoad.Entries {
|
|
|
|
if !entryLoad.ID.Equal(entryNew.ID) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if entryLoad.Type != entryNew.Type {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if entryLoad.Offset != entryNew.Offset {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if entryLoad.Length != entryNew.Length {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
found = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
if !found {
|
|
|
|
t.Errorf("blob not found in loaded index: %v", entryNew)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-07 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkIndexNew(b *testing.B) {
|
2016-08-07 19:56:06 +00:00
|
|
|
repo, cleanup := createFilledRepo(b, 3, 0)
|
2016-08-07 15:19:00 +00:00
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
2017-06-15 13:03:05 +00:00
|
|
|
idx, _, err := New(context.TODO(), repo, restic.NewIDSet(), nil)
|
2016-08-07 15:19:00 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
b.Fatalf("New() returned error %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if idx == nil {
|
|
|
|
b.Fatalf("New() returned nil index")
|
|
|
|
}
|
2017-01-15 15:16:09 +00:00
|
|
|
b.Logf("idx %v packs", len(idx.Packs))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkIndexSave(b *testing.B) {
|
2017-01-17 12:00:59 +00:00
|
|
|
repo, cleanup := repository.TestRepository(b)
|
2017-01-15 15:16:09 +00:00
|
|
|
defer cleanup()
|
|
|
|
|
2017-06-15 13:03:05 +00:00
|
|
|
idx, _, err := New(context.TODO(), repo, restic.NewIDSet(), nil)
|
2017-01-15 15:16:09 +00:00
|
|
|
test.OK(b, err)
|
|
|
|
|
2017-01-17 12:00:59 +00:00
|
|
|
for i := 0; i < 8000; i++ {
|
|
|
|
entries := make([]restic.Blob, 0, 200)
|
2017-01-22 08:59:19 +00:00
|
|
|
for j := 0; j < cap(entries); j++ {
|
2017-01-17 12:00:59 +00:00
|
|
|
entries = append(entries, restic.Blob{
|
|
|
|
ID: restic.NewRandomID(),
|
|
|
|
Length: 1000,
|
|
|
|
Offset: 5,
|
|
|
|
Type: restic.DataBlob,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
idx.AddPack(restic.NewRandomID(), 10000, entries)
|
|
|
|
}
|
|
|
|
|
2017-01-15 15:16:09 +00:00
|
|
|
b.ResetTimer()
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
2018-01-25 21:03:54 +00:00
|
|
|
ids, err := idx.Save(context.TODO(), repo, nil)
|
2017-01-15 15:16:09 +00:00
|
|
|
if err != nil {
|
|
|
|
b.Fatalf("New() returned error %v", err)
|
|
|
|
}
|
|
|
|
|
2018-01-25 21:03:54 +00:00
|
|
|
b.Logf("saved as %v", ids)
|
2016-08-07 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-07 19:57:31 +00:00
|
|
|
|
|
|
|
func TestIndexDuplicateBlobs(t *testing.T) {
|
2018-10-28 13:02:31 +00:00
|
|
|
repo, cleanup := createFilledRepo(t, 3, 0.05)
|
2016-08-07 19:57:31 +00:00
|
|
|
defer cleanup()
|
|
|
|
|
2017-06-15 13:03:05 +00:00
|
|
|
idx, _, err := New(context.TODO(), repo, restic.NewIDSet(), nil)
|
2016-08-07 19:57:31 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
dups := idx.DuplicateBlobs()
|
|
|
|
if len(dups) == 0 {
|
|
|
|
t.Errorf("no duplicate blobs found")
|
|
|
|
}
|
2017-01-15 14:45:52 +00:00
|
|
|
t.Logf("%d packs, %d duplicate blobs", len(idx.Packs), len(dups))
|
2016-08-07 20:18:20 +00:00
|
|
|
|
|
|
|
packs := idx.PacksForBlobs(dups)
|
|
|
|
if len(packs) == 0 {
|
|
|
|
t.Errorf("no packs with duplicate blobs found")
|
|
|
|
}
|
|
|
|
t.Logf("%d packs with duplicate blobs", len(packs))
|
2016-08-07 19:57:31 +00:00
|
|
|
}
|
2016-08-14 11:38:59 +00:00
|
|
|
|
2016-09-03 11:34:04 +00:00
|
|
|
func loadIndex(t testing.TB, repo restic.Repository) *Index {
|
2017-06-05 21:56:59 +00:00
|
|
|
idx, err := Load(context.TODO(), repo, nil)
|
2016-08-14 11:38:59 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Load() returned error %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return idx
|
|
|
|
}
|
|
|
|
|
2017-01-20 13:46:14 +00:00
|
|
|
func TestIndexSave(t *testing.T) {
|
|
|
|
repo, cleanup := createFilledRepo(t, 3, 0)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
idx := loadIndex(t, repo)
|
|
|
|
|
2018-01-25 21:03:54 +00:00
|
|
|
ids, err := idx.Save(context.TODO(), repo, idx.IndexIDs.List())
|
2017-01-20 13:46:14 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unable to save new index: %v", err)
|
|
|
|
}
|
|
|
|
|
2018-01-25 21:03:54 +00:00
|
|
|
t.Logf("new index saved as %v", ids)
|
2017-01-20 13:46:14 +00:00
|
|
|
|
|
|
|
for id := range idx.IndexIDs {
|
|
|
|
t.Logf("remove index %v", id.Str())
|
2017-01-25 16:48:35 +00:00
|
|
|
h := restic.Handle{Type: restic.IndexFile, Name: id.String()}
|
2017-06-05 21:56:59 +00:00
|
|
|
err = repo.Backend().Remove(context.TODO(), h)
|
2017-01-20 13:46:14 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("error removing index %v: %v", id, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
idx2 := loadIndex(t, repo)
|
|
|
|
t.Logf("load new index with %d packs", len(idx2.Packs))
|
|
|
|
|
|
|
|
checker := checker.New(repo)
|
2017-06-05 21:56:59 +00:00
|
|
|
hints, errs := checker.LoadIndex(context.TODO())
|
2017-01-20 13:46:14 +00:00
|
|
|
for _, h := range hints {
|
|
|
|
t.Logf("hint: %v\n", h)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, err := range errs {
|
|
|
|
t.Errorf("checker found error: %v", err)
|
|
|
|
}
|
2018-01-25 20:59:11 +00:00
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.TODO())
|
2018-10-28 10:17:04 +00:00
|
|
|
defer cancel()
|
2018-01-25 20:59:11 +00:00
|
|
|
|
|
|
|
errCh := make(chan error)
|
|
|
|
go checker.Structure(ctx, errCh)
|
|
|
|
i := 0
|
|
|
|
for err := range errCh {
|
|
|
|
t.Errorf("checker returned error: %v", err)
|
|
|
|
i++
|
|
|
|
if i == 10 {
|
|
|
|
t.Errorf("more than 10 errors returned, skipping the rest")
|
|
|
|
cancel()
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2017-01-20 13:46:14 +00:00
|
|
|
}
|
|
|
|
|
2016-08-15 16:55:52 +00:00
|
|
|
func TestIndexAddRemovePack(t *testing.T) {
|
|
|
|
repo, cleanup := createFilledRepo(t, 3, 0)
|
|
|
|
defer cleanup()
|
|
|
|
|
2017-06-05 21:56:59 +00:00
|
|
|
idx, err := Load(context.TODO(), repo, nil)
|
2016-08-15 16:55:52 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Load() returned error %v", err)
|
|
|
|
}
|
|
|
|
|
2018-01-21 16:25:36 +00:00
|
|
|
var packID restic.ID
|
|
|
|
err = repo.List(context.TODO(), restic.DataFile, func(id restic.ID, size int64) error {
|
|
|
|
packID = id
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-08-15 16:55:52 +00:00
|
|
|
|
|
|
|
t.Logf("selected pack %v", packID.Str())
|
|
|
|
|
|
|
|
blobs := idx.Packs[packID].Entries
|
|
|
|
|
|
|
|
idx.RemovePack(packID)
|
|
|
|
|
|
|
|
if _, ok := idx.Packs[packID]; ok {
|
|
|
|
t.Errorf("removed pack %v found in index.Packs", packID.Str())
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, blob := range blobs {
|
2016-08-31 21:07:50 +00:00
|
|
|
h := restic.BlobHandle{ID: blob.ID, Type: blob.Type}
|
2016-08-15 16:55:52 +00:00
|
|
|
_, err := idx.FindBlob(h)
|
|
|
|
if err == nil {
|
|
|
|
t.Errorf("removed blob %v found in index", h)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-15 18:35:45 +00:00
|
|
|
// example index serialization from doc/Design.rst
|
2016-08-14 12:47:02 +00:00
|
|
|
var docExample = []byte(`
|
|
|
|
{
|
|
|
|
"supersedes": [
|
|
|
|
"ed54ae36197f4745ebc4b54d10e0f623eaaaedd03013eb7ae90df881b7781452"
|
|
|
|
],
|
|
|
|
"packs": [
|
|
|
|
{
|
|
|
|
"id": "73d04e6125cf3c28a299cc2f3cca3b78ceac396e4fcf9575e34536b26782413c",
|
|
|
|
"blobs": [
|
|
|
|
{
|
|
|
|
"id": "3ec79977ef0cf5de7b08cd12b874cd0f62bbaf7f07f3497a5b1bbcc8cb39b1ce",
|
|
|
|
"type": "data",
|
|
|
|
"offset": 0,
|
|
|
|
"length": 25
|
|
|
|
},{
|
|
|
|
"id": "9ccb846e60d90d4eb915848add7aa7ea1e4bbabfc60e573db9f7bfb2789afbae",
|
|
|
|
"type": "tree",
|
|
|
|
"offset": 38,
|
|
|
|
"length": 100
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id": "d3dc577b4ffd38cc4b32122cabf8655a0223ed22edfd93b353dc0c3f2b0fdf66",
|
|
|
|
"type": "data",
|
|
|
|
"offset": 150,
|
|
|
|
"length": 123
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
func TestIndexLoadDocReference(t *testing.T) {
|
|
|
|
repo, cleanup := repository.TestRepository(t)
|
|
|
|
defer cleanup()
|
|
|
|
|
2017-06-05 21:56:59 +00:00
|
|
|
id, err := repo.SaveUnpacked(context.TODO(), restic.IndexFile, docExample)
|
2016-08-14 12:47:02 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("SaveUnpacked() returned error %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Logf("index saved as %v", id.Str())
|
|
|
|
|
|
|
|
idx := loadIndex(t, repo)
|
|
|
|
|
2016-09-04 12:38:18 +00:00
|
|
|
blobID := restic.TestParseID("d3dc577b4ffd38cc4b32122cabf8655a0223ed22edfd93b353dc0c3f2b0fdf66")
|
2016-08-31 21:07:50 +00:00
|
|
|
locs, err := idx.FindBlob(restic.BlobHandle{ID: blobID, Type: restic.DataBlob})
|
2016-08-14 12:47:02 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("FindBlob() returned error %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(locs) != 1 {
|
|
|
|
t.Errorf("blob found %d times, expected just one", len(locs))
|
|
|
|
}
|
|
|
|
|
|
|
|
l := locs[0]
|
|
|
|
if !l.ID.Equal(blobID) {
|
|
|
|
t.Errorf("blob IDs are not equal: %v != %v", l.ID, blobID)
|
|
|
|
}
|
|
|
|
|
2016-08-31 21:07:50 +00:00
|
|
|
if l.Type != restic.DataBlob {
|
|
|
|
t.Errorf("want type %v, got %v", restic.DataBlob, l.Type)
|
2016-08-14 12:47:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if l.Offset != 150 {
|
|
|
|
t.Errorf("wrong offset, want %d, got %v", 150, l.Offset)
|
|
|
|
}
|
|
|
|
|
|
|
|
if l.Length != 123 {
|
|
|
|
t.Errorf("wrong length, want %d, got %v", 123, l.Length)
|
|
|
|
}
|
|
|
|
}
|