From 50fd8f6f44dc27e5264de4b8a073e443c31b579f Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Mon, 26 Oct 2015 20:49:01 +0100 Subject: [PATCH] make repo for tree walker mockable --- tree.go | 7 +++++-- walk.go | 5 ++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tree.go b/tree.go index 8d94d208e..b4d340ee2 100644 --- a/tree.go +++ b/tree.go @@ -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 { diff --git a/walk.go b/walk.go index 53b89b748..1e5979328 100644 --- a/walk.go +++ b/walk.go @@ -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)