Move FindUsedBlobs to package restic

This commit is contained in:
Alexander Neumann 2016-08-01 18:31:44 +02:00
parent 22aa17091b
commit 723592d923
4 changed files with 54 additions and 42 deletions

12
src/restic/find.go Normal file
View File

@ -0,0 +1,12 @@
package restic
import (
"restic/backend"
"restic/repository"
)
// FindUsedBlobs traverses the tree ID and returns a set of all blobs
// encountered.
func FindUsedBlobs(repo *repository.Repository, treeID backend.ID) (backend.IDSet, error) {
return nil, nil
}

42
src/restic/find_test.go Normal file
View File

@ -0,0 +1,42 @@
package restic
import (
"testing"
"time"
"restic/repository"
)
const (
testSnapshots = 3
testDepth = 2
)
var testTime = time.Unix(1469960361, 23)
func TestFindUsedBlobs(t *testing.T) {
repo, cleanup := repository.TestRepository(t)
defer cleanup()
var snapshots []*Snapshot
for i := 0; i < testSnapshots; i++ {
sn := TestCreateSnapshot(t, repo, testTime.Add(time.Duration(i)*time.Second), testDepth)
t.Logf("snapshot %v saved, tree %v", sn.ID().Str(), sn.Tree.Str())
snapshots = append(snapshots, sn)
}
for _, sn := range snapshots {
usedBlobs, err := FindUsedBlobs(repo, *sn.Tree)
if err != nil {
t.Errorf("FindUsedBlobs returned error: %v", err)
continue
}
if len(usedBlobs) == 0 {
t.Errorf("FindUsedBlobs returned an empty set")
continue
}
t.Logf("used blobs from snapshot %v (tree %v): %v", sn.ID().Str(), sn.Tree.Str(), usedBlobs)
}
}

View File

@ -174,9 +174,3 @@ func RebuildIndex(repo *Repository) error {
return nil
}
// FindUsedBlobs traverses the tree ID and returns a set of all blobs
// encountered.
func FindUsedBlobs(repo *Repository, treeID backend.ID) (backend.IDSet, error) {
return nil, nil
}

View File

@ -3,12 +3,10 @@ package repository_test
import (
"io"
"math/rand"
"restic"
"restic/backend"
"restic/pack"
"restic/repository"
"testing"
"time"
)
func randomSize(min, max int) int {
@ -192,37 +190,3 @@ func TestRepack(t *testing.T) {
}
}
}
const (
testSnapshots = 3
testDepth = 2
)
var testTime = time.Unix(1469960361, 23)
func TestFindUsedBlobs(t *testing.T) {
repo, cleanup := repository.TestRepository(t)
defer cleanup()
var snapshots []*restic.Snapshot
for i := 0; i < testSnapshots; i++ {
sn := restic.TestCreateSnapshot(t, repo, testTime.Add(time.Duration(i)*time.Second), testDepth)
t.Logf("snapshot %v saved, tree %v", sn.ID().Str(), sn.Tree.Str())
snapshots = append(snapshots, sn)
}
for _, sn := range snapshots {
usedBlobs, err := repository.FindUsedBlobs(repo, *sn.Tree)
if err != nil {
t.Errorf("FindUsedBlobs returned error: %v", err)
continue
}
if len(usedBlobs) == 0 {
t.Errorf("FindUsedBlobs returned an empty set")
continue
}
t.Logf("used blobs from snapshot %v (tree %v): %v", sn.ID().Str(), sn.Tree.Str(), usedBlobs)
}
}