summaryrefslogtreecommitdiff
path: root/branch_test.go
diff options
context:
space:
mode:
authorDavid Calavera <[email protected]>2015-02-18 15:32:50 +0530
committerCarlos Martín Nieto <[email protected]>2015-02-19 11:44:56 +0100
commit755721e68453c5d6de0681789dbe3307744fc9c4 (patch)
treefd72784084bb7a60982569af51e891195855400c /branch_test.go
parent94b1f7d07dd3786de15f44e3faf2a3e4d680a0b8 (diff)
Add BranchIterator#ForEach.
This abstracts the branch iteration from the user.
Diffstat (limited to 'branch_test.go')
-rw-r--r--branch_test.go37
1 files changed, 33 insertions, 4 deletions
diff --git a/branch_test.go b/branch_test.go
index 44f6338..09ebeba 100644
--- a/branch_test.go
+++ b/branch_test.go
@@ -1,11 +1,8 @@
package git
-import (
- "testing"
-)
+import "testing"
func TestBranchIterator(t *testing.T) {
-
repo := createTestRepo(t)
seedTestRepo(t, repo)
@@ -24,3 +21,35 @@ func TestBranchIterator(t *testing.T) {
t.Fatal("expected iterover")
}
}
+
+func TestBranchIteratorEach(t *testing.T) {
+ repo := createTestRepo(t)
+ seedTestRepo(t, repo)
+
+ i, err := repo.NewBranchIterator(BranchLocal)
+ checkFatal(t, err)
+
+ var names []string
+ f := func(b *Branch, t BranchType) error {
+ name, err := b.Name()
+ if err != nil {
+ return err
+ }
+
+ names = append(names, name)
+ return nil
+ }
+
+ err = i.ForEach(f)
+ if err != nil && !IsErrorCode(err, ErrIterOver) {
+ t.Fatal(err)
+ }
+
+ if len(names) != 1 {
+ t.Fatalf("expect 1 branch, but it was %d\n", len(names))
+ }
+
+ if names[0] != "master" {
+ t.Fatalf("expect branch master, but it was %s\n", names[0])
+ }
+}