diff options
| author | Carlos Martín Nieto <[email protected]> | 2014-05-06 14:19:34 +0200 |
|---|---|---|
| committer | Carlos Martín Nieto <[email protected]> | 2014-05-06 14:19:34 +0200 |
| commit | 2594f3f889f93196bc9707ca6962f4f773806f10 (patch) | |
| tree | a12564217e46557719bb796e8c82138d66ce48a9 /odb_test.go | |
| parent | 9a8b80fc13b923b46b44fbd969e01db6d9f4b7b9 (diff) | |
Odb: use a callback instead of a channel for ForEach
A channel provides no way to specify whether we stopped sending data
because of an error or because there is no more data.
Therefore, make Odb.ForEach() take a callback with which the user is free to
do whatever they need, letting us return en error.
Diffstat (limited to 'odb_test.go')
| -rw-r--r-- | odb_test.go | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/odb_test.go b/odb_test.go index 17b3ad2..14a3658 100644 --- a/odb_test.go +++ b/odb_test.go @@ -3,6 +3,7 @@ package git import ( "io" "os" + "errors" "testing" ) @@ -48,7 +49,7 @@ parent 66e1c476199ebcd3e304659992233132c5a52c6c author John Doe <[email protected]> 1390682018 +0000 committer John Doe <[email protected]> 1390682018 +0000 -Initial commit.`; +Initial commit.` oid, error := odb.Hash([]byte(str), ObjectCommit) checkFatal(t, error) @@ -60,3 +61,36 @@ Initial commit.`; t.Fatal("Hash and write Oids are different") } } + +func TestOdbForeach(t *testing.T) { + repo := createTestRepo(t) + defer os.RemoveAll(repo.Workdir()) + _, _ = seedTestRepo(t, repo) + + odb, err := repo.Odb() + checkFatal(t, err) + + expect := 3 + count := 0 + err = odb.ForEach(func(id *Oid) error { + count++ + return nil + }) + + checkFatal(t, err) + if count != expect { + t.Fatalf("Expected %v objects, got %v") + } + + expect = 1 + count = 0 + to_return := errors.New("not really an error") + err = odb.ForEach(func(id *Oid) error { + count++ + return to_return + }) + + if err != to_return { + t.Fatalf("Odb.ForEach() did not return the expected error, got %v", err) + } +} |
