diff options
| author | Carlos Martín Nieto <[email protected]> | 2015-03-15 01:09:11 +0100 |
|---|---|---|
| committer | Carlos Martín Nieto <[email protected]> | 2015-03-15 01:09:11 +0100 |
| commit | 137c4fc3c838a803dddeb2855e726fc30713fdea (patch) | |
| tree | cc2bbc371b93ed92d4b2f3a1abc2a62d6d578277 /branch_test.go | |
| parent | 063bed33a90e7d5b1ece1b6bd1aba04a69a78a28 (diff) | |
| parent | 76d600f7b3633f78e5f1433c16eba4eddfdad3e0 (diff) | |
Merge branch 'master' into v22
Diffstat (limited to 'branch_test.go')
| -rw-r--r-- | branch_test.go | 37 |
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]) + } +} |
