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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
package git
import (
"gopkg.in/src-d/go-git.v2/clients/http"
"gopkg.in/src-d/go-git.v2/core"
. "gopkg.in/check.v1"
)
type SuiteRepository struct{}
var _ = Suite(&SuiteRepository{})
func (s *SuiteRepository) TestNewRepository(c *C) {
r, err := NewRepository(RepositoryFixture, nil)
c.Assert(err, IsNil)
c.Assert(r.Remotes["origin"].Auth, IsNil)
c.Assert(r.URL, Equals, RepositoryFixture)
}
func (s *SuiteRepository) TestNewRepositoryWithAuth(c *C) {
auth := &http.BasicAuth{}
r, err := NewRepository(RepositoryFixture, auth)
c.Assert(err, IsNil)
c.Assert(r.Remotes["origin"].Auth, Equals, auth)
}
func (s *SuiteRepository) TestPull(c *C) {
r, err := NewRepository(RepositoryFixture, nil)
r.Remotes["origin"].upSrv = &MockGitUploadPackService{}
c.Assert(err, IsNil)
c.Assert(r.Pull("origin", "refs/heads/master"), IsNil)
}
func (s *SuiteRepository) TestCommit(c *C) {
r, err := NewRepository(RepositoryFixture, nil)
r.Remotes["origin"].upSrv = &MockGitUploadPackService{}
c.Assert(err, IsNil)
c.Assert(r.Pull("origin", "refs/heads/master"), IsNil)
hash := core.NewHash("b8e471f58bcbca63b07bda20e428190409c2db47")
commit, err := r.Commit(hash)
c.Assert(err, IsNil)
c.Assert(commit.Hash.IsZero(), Equals, false)
c.Assert(commit.Tree().Hash.IsZero(), Equals, false)
c.Assert(commit.Author.Email, Equals, "daniel@lordran.local")
}
func (s *SuiteRepository) TestCommits(c *C) {
r, err := NewRepository(RepositoryFixture, nil)
r.Remotes["origin"].upSrv = &MockGitUploadPackService{}
c.Assert(err, IsNil)
c.Assert(r.Pull("origin", "refs/heads/master"), IsNil)
count := 0
commits := r.Commits()
for {
commit, err := commits.Next()
if err != nil {
break
}
count++
c.Assert(commit.Hash.IsZero(), Equals, false)
//c.Assert(commit.Tree.IsZero(), Equals, false)
}
c.Assert(count, Equals, 8)
}
func (s *SuiteRepository) TestCommitIterClosePanic(c *C) {
r, err := NewRepository(RepositoryFixture, nil)
r.Remotes["origin"].upSrv = &MockGitUploadPackService{}
c.Assert(err, IsNil)
c.Assert(r.Pull("origin", "refs/heads/master"), IsNil)
commits := r.Commits()
commits.Close()
}
|