2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-26 14:56:29 +00:00

make repo for tree walker mockable

This commit is contained in:
Alexander Neumann 2015-10-26 20:49:01 +01:00
parent 7711fcda69
commit 50fd8f6f44
2 changed files with 7 additions and 5 deletions

View File

@ -8,7 +8,6 @@ import (
"github.com/restic/restic/backend"
"github.com/restic/restic/debug"
"github.com/restic/restic/pack"
"github.com/restic/restic/repository"
)
type Tree struct {
@ -30,7 +29,11 @@ func (t Tree) String() string {
return fmt.Sprintf("Tree<%d nodes>", len(t.Nodes))
}
func LoadTree(repo *repository.Repository, id backend.ID) (*Tree, error) {
type TreeLoader interface {
LoadJSONPack(pack.BlobType, backend.ID, interface{}) error
}
func LoadTree(repo TreeLoader, id backend.ID) (*Tree, error) {
tree := &Tree{}
err := repo.LoadJSONPack(pack.Tree, id, tree)
if err != nil {

View File

@ -5,7 +5,6 @@ import (
"github.com/restic/restic/backend"
"github.com/restic/restic/debug"
"github.com/restic/restic/repository"
)
type WalkTreeJob struct {
@ -16,7 +15,7 @@ type WalkTreeJob struct {
Tree *Tree
}
func walkTree(repo *repository.Repository, path string, treeID backend.ID, done chan struct{}, jobCh chan<- WalkTreeJob) {
func walkTree(repo TreeLoader, path string, treeID backend.ID, done chan struct{}, jobCh chan<- WalkTreeJob) {
debug.Log("walkTree", "start on %q (%v)", path, treeID.Str())
t, err := LoadTree(repo, treeID)
@ -54,7 +53,7 @@ func walkTree(repo *repository.Repository, path string, treeID backend.ID, done
// WalkTree walks the tree specified by id recursively and sends a job for each
// file and directory it finds. When the channel done is closed, processing
// stops.
func WalkTree(repo *repository.Repository, id backend.ID, done chan struct{}, jobCh chan<- WalkTreeJob) {
func WalkTree(repo TreeLoader, id backend.ID, done chan struct{}, jobCh chan<- WalkTreeJob) {
debug.Log("WalkTree", "start on %v", id.Str())
walkTree(repo, "", id, done, jobCh)
close(jobCh)