- Notifications
You must be signed in to change notification settings - Fork 324
/
Copy pathbranch_test.go
63 lines (50 loc) · 1.17 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"
)
funcTestBranchIterator(t*testing.T) {
t.Parallel()
repo:=createTestRepo(t)
defercleanupTestRepo(t, repo)
seedTestRepo(t, repo)
i, err:=repo.NewBranchIterator(BranchLocal)
checkFatal(t, err)
b, bt, err:=i.Next()
checkFatal(t, err)
ifname, _:=b.Name(); name!="master" {
t.Fatalf("expected master")
} elseifbt!=BranchLocal {
t.Fatalf("expected BranchLocal, not %v", t)
}
b, bt, err=i.Next()
if!IsErrorCode(err, ErrorCodeIterOver) {
t.Fatal("expected iterover")
}
}
funcTestBranchIteratorEach(t*testing.T) {
t.Parallel()
repo:=createTestRepo(t)
defercleanupTestRepo(t, repo)
seedTestRepo(t, repo)
i, err:=repo.NewBranchIterator(BranchLocal)
checkFatal(t, err)
varnames []string
f:=func(b*Branch, tBranchType) error {
name, err:=b.Name()
iferr!=nil {
returnerr
}
names=append(names, name)
returnnil
}
err=i.ForEach(f)
iferr!=nil&&!IsErrorCode(err, ErrorCodeIterOver) {
t.Fatal(err)
}
iflen(names) !=1 {
t.Fatalf("expect 1 branch, but it was %d\n", len(names))
}
ifnames[0] !="master" {
t.Fatalf("expect branch master, but it was %s\n", names[0])
}
}