forked from libgit2/git2go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
branch_test.go
63 lines (50 loc) · 1.16 KB
/
branch_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package git
import (
"testing"
)
func TestBranchIterator(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
seedTestRepo(t, repo)
i, err := repo.NewBranchIterator(BranchLocal)
checkFatal(t, err)
b, bt, err := i.Next()
checkFatal(t, err)
if name, _ := b.Name(); name != "master" {
t.Fatalf("expected master")
} else if bt != BranchLocal {
t.Fatalf("expected BranchLocal, not %v", t)
}
b, bt, err = i.Next()
if !IsErrorCode(err, ErrIterOver) {
t.Fatal("expected iterover")
}
}
func TestBranchIteratorEach(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
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])
}
}