summaryrefslogtreecommitdiff
path: root/branch_test.go
blob: 7db509bcc74f2f8310cfabe5506b785af15c6d76 (plain)
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
package git

import (
	"testing"
)

func TestBranchIterator(t *testing.T) {

	repo := createTestRepo(t)
	seedTestRepo(t, repo)

	i, err := repo.NewBranchIterator(BranchLocal)
	checkFatal(t, err)

	ref, err := i.Next()
	checkFatal(t, err)
	if ref.Name() != "refs/heads/master" {
		t.Fatalf("expected refs/heads/master, not %v", ref.Name())
	}
	ref, err = i.Next()
	if ref != nil {
		t.Fatal("expected nil")
	}

	if err != ErrIterOver {
		t.Fatal("expected iterover")
	}

	// test channel iterator

	i, err = repo.NewBranchIterator(BranchLocal)
	checkFatal(t, err)

	list := make([]string, 0)
	for ref := range ReferenceNameIteratorChannel(i) {
		list = append(list, ref)
	}

	if len(list) != 1 {
		t.Fatal("expected single match")
	}

	if list[0] != "refs/heads/master" {
		t.Fatal("expected refs/heads/master")
	}

}