2014-03-12 17:49:11 -05:00
|
|
|
package git
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2014-03-19 02:19:02 -05:00
|
|
|
func TestBranchIterator(t *testing.T) {
|
2014-03-12 17:49:11 -05:00
|
|
|
|
|
|
|
repo := createTestRepo(t)
|
|
|
|
seedTestRepo(t, repo)
|
|
|
|
|
|
|
|
i, err := repo.NewBranchIterator(BranchLocal)
|
|
|
|
checkFatal(t, err)
|
|
|
|
|
2014-03-19 22:24:19 -05:00
|
|
|
b, err := i.NextBranch()
|
2014-03-12 17:49:11 -05:00
|
|
|
checkFatal(t, err)
|
2014-03-19 22:24:19 -05:00
|
|
|
if name, _ := b.Branch.Name(); name != "master" {
|
|
|
|
t.Fatalf("expected master")
|
2014-03-12 17:49:11 -05:00
|
|
|
}
|
2014-03-19 22:24:19 -05:00
|
|
|
if b.Type != BranchLocal {
|
|
|
|
t.Fatalf("expected BranchLocal, not %v", t)
|
2014-03-12 17:49:11 -05:00
|
|
|
}
|
2014-03-19 22:24:19 -05:00
|
|
|
b, err = i.NextBranch()
|
2014-03-12 17:49:11 -05:00
|
|
|
if err != ErrIterOver {
|
|
|
|
t.Fatal("expected iterover")
|
|
|
|
}
|
2014-03-19 02:19:02 -05:00
|
|
|
|
|
|
|
// test channel iterator
|
|
|
|
|
|
|
|
i, err = repo.NewBranchIterator(BranchLocal)
|
|
|
|
checkFatal(t, err)
|
|
|
|
|
|
|
|
list := make([]string, 0)
|
2014-03-19 02:36:00 -05:00
|
|
|
for ref := range NameIteratorChannel(i) {
|
2014-03-19 02:19:02 -05:00
|
|
|
list = append(list, ref)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(list) != 1 {
|
|
|
|
t.Fatal("expected single match")
|
|
|
|
}
|
|
|
|
|
2014-03-19 22:24:19 -05:00
|
|
|
if list[0] != "master" {
|
|
|
|
t.Fatal("expected master")
|
2014-03-19 02:19:02 -05:00
|
|
|
}
|
|
|
|
|
2014-03-12 17:49:11 -05:00
|
|
|
}
|