aboutsummaryrefslogtreecommitdiffstats
path: root/repository_test.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-08-13 22:32:34 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2016-08-13 22:32:34 +0200
commit79087748f60f9aba219624a0fe9f4d33a0b51236 (patch)
tree1c0d17543ad742d1e97276796140f8b398b74802 /repository_test.go
parenta65bcbc63bef24cf219c63d1b8cfb309c95d1c0f (diff)
downloadgo-git-79087748f60f9aba219624a0fe9f4d33a0b51236.tar.gz
Repository.Clone and Remote.Fetch tests and improvements
Diffstat (limited to 'repository_test.go')
-rw-r--r--repository_test.go135
1 files changed, 59 insertions, 76 deletions
diff --git a/repository_test.go b/repository_test.go
index 3ca4d0d..80bd0d1 100644
--- a/repository_test.go
+++ b/repository_test.go
@@ -60,58 +60,68 @@ func (s *RepositorySuite) TearDownSuite(c *C) {
}
}
-/*
func (s *RepositorySuite) TestNewRepository(c *C) {
- r, err := NewRepository(RepositoryFixture, nil)
+ r, err := NewMemoryRepository()
c.Assert(err, IsNil)
- c.Assert(r.Remotes["origin"].Auth, IsNil)
+ c.Assert(r, NotNil)
}
-func (s *RepositorySuite) TestNewRepositoryWithAuth(c *C) {
- auth := &http.BasicAuth{}
- r, err := NewRepository(RepositoryFixture, auth)
+func (s *RepositorySuite) TestClone(c *C) {
+ r, err := NewMemoryRepository()
c.Assert(err, IsNil)
- c.Assert(r.Remotes["origin"].Auth, Equals, auth)
-}
+ c.Assert(r.Remotes, HasLen, 0)
-func (s *RepositorySuite) TestNewRepositoryFromFS(c *C) {
- for name, fix := range s.dirFixtures {
- fs := fs.NewOS()
- gitPath := fs.Join(fix.path, ".git/")
- com := Commentf("dir fixture %q → %q\n", name, gitPath)
- repo, err := NewRepositoryFromFS(fs, gitPath)
- c.Assert(err, IsNil, com)
+ head, err := r.Head()
+ c.Assert(err, Equals, core.ErrReferenceNotFound)
+ c.Assert(head, IsNil)
- err = repo.PullDefault()
- c.Assert(err, ErrorMatches, `unable to find remote "origin"`)
+ err = r.Clone(&CloneOptions{
+ URL: RepositoryFixture,
+ })
- c.Assert(repo.Storage, NotNil, com)
- c.Assert(repo.Storage, FitsTypeOf, &filesystem.ObjectStorage{}, com)
- }
-}
+ c.Assert(err, IsNil)
+ c.Assert(r.Remotes, HasLen, 1)
+ c.Assert(r.Remotes[DefaultRemoteName], NotNil)
+ head, err = r.Ref(core.HEAD, false)
+ c.Assert(err, IsNil)
+ c.Assert(head, NotNil)
+ c.Assert(head.Type(), Equals, core.SymbolicReference)
+ c.Assert(head.Target().String(), Equals, "refs/heads/master")
-func (s *RepositorySuite) TestClone(c *C) {
- r, err := NewRepository(RepositoryFixture, nil)
- r.Remotes["origin"].upSrv = &MockGitUploadPackService{}
+ branch, err := r.Ref(head.Target(), false)
+ c.Assert(err, IsNil)
+ c.Assert(branch, NotNil)
+ c.Assert(branch.Hash().String(), Equals, "6ecf0ef2c2dffb796033e5a02219af86ec6584e5")
+}
+func (s *RepositorySuite) TestCloneDetachedHEAD(c *C) {
+ r, err := NewMemoryRepository()
c.Assert(err, IsNil)
- c.Assert(r.Pull("origin", "refs/heads/master"), IsNil)
- mock, ok := (r.Remotes["origin"].upSrv).(*MockGitUploadPackService)
- c.Assert(ok, Equals, true)
- err = mock.RC.Close()
- c.Assert(err, Not(IsNil), Commentf("pull leaks an open fd from the fetch"))
-}
+ c.Assert(r.Remotes, HasLen, 0)
+ err = r.Clone(&CloneOptions{
+ URL: RepositoryFixture,
+ ReferenceName: core.ReferenceName("refs/tags/v1.0.0"),
+ })
+ head, err := r.Ref(core.HEAD, false)
+ c.Assert(err, IsNil)
+ c.Assert(head, NotNil)
+ c.Assert(head.Type(), Equals, core.HashReference)
+ c.Assert(head.Hash().String(), Equals, "6ecf0ef2c2dffb796033e5a02219af86ec6584e5")
+}
func (s *RepositorySuite) TestCommit(c *C) {
- r, err := NewRepository(RepositoryFixture, nil)
- r.Remotes["origin"].upSrv = &MockGitUploadPackService{}
+ r, err := NewMemoryRepository()
+ c.Assert(err, IsNil)
+
+ err = r.Clone(&CloneOptions{
+ URL: RepositoryFixture,
+ })
c.Assert(err, IsNil)
- c.Assert(r.Pull("origin", "refs/heads/master"), IsNil)
hash := core.NewHash("b8e471f58bcbca63b07bda20e428190409c2db47")
commit, err := r.Commit(hash)
@@ -124,7 +134,6 @@ func (s *RepositorySuite) TestCommit(c *C) {
c.Assert(commit.Tree().Hash.IsZero(), Equals, false)
c.Assert(commit.Author.Email, Equals, "daniel@lordran.local")
}
-*/
func (s *RepositorySuite) TestCommits(c *C) {
r, err := NewMemoryRepository()
@@ -192,67 +201,41 @@ func (s *RepositorySuite) TestObject(c *C) {
}
}
-/*
func (s *RepositorySuite) TestCommitIterClosePanic(c *C) {
- r, err := NewRepository(RepositoryFixture, nil)
- r.Remotes["origin"].upSrv = &MockGitUploadPackService{}
+ r, err := NewMemoryRepository()
+ c.Assert(err, IsNil)
+ err = r.Clone(&CloneOptions{URL: RepositoryFixture})
c.Assert(err, IsNil)
- c.Assert(r.Pull("origin", "refs/heads/master"), IsNil)
commits, err := r.Commits()
c.Assert(err, IsNil)
commits.Close()
}
-
-func (s *RepositorySuite) TestHeadFromFs(c *C) {
- for name, fix := range s.dirFixtures {
- fs := fs.NewOS()
- gitPath := fs.Join(fix.path, ".git/")
- com := Commentf("dir fixture %q → %q\n", name, gitPath)
- repo, err := NewRepositoryFromFS(fs, gitPath)
- c.Assert(err, IsNil, com)
-
- head, err := repo.Head("")
- c.Assert(err, IsNil)
-
- c.Assert(head, Equals, fix.head)
- }
-}
-
-func (s *RepositorySuite) TestHeadFromRemote(c *C) {
- r, err := NewRepository(RepositoryFixture, nil)
+func (s *RepositorySuite) TestRef(c *C) {
+ r, err := NewMemoryRepository()
c.Assert(err, IsNil)
- upSrv := &MockGitUploadPackService{}
- r.Remotes[DefaultRemoteName].upSrv = upSrv
- err = r.Remotes[DefaultRemoteName].Connect()
+ err = r.Clone(&CloneOptions{URL: RepositoryFixture})
c.Assert(err, IsNil)
- info, err := upSrv.Info()
+ ref, err := r.Ref(core.HEAD, false)
c.Assert(err, IsNil)
- expected := info.Head
+ c.Assert(ref.Name(), Equals, core.HEAD)
- obtained, err := r.Head(DefaultRemoteName)
+ ref, err = r.Ref(core.HEAD, true)
c.Assert(err, IsNil)
-
- c.Assert(obtained, Equals, expected)
+ c.Assert(ref.Name(), Equals, core.ReferenceName("refs/heads/master"))
}
-func (s *RepositorySuite) TestHeadErrors(c *C) {
- r, err := NewRepository(RepositoryFixture, nil)
+func (s *RepositorySuite) TestRefs(c *C) {
+ r, err := NewMemoryRepository()
c.Assert(err, IsNil)
- upSrv := &MockGitUploadPackService{}
- r.Remotes[DefaultRemoteName].upSrv = upSrv
-
- remote := "not found"
- _, err = r.Head(remote)
- c.Assert(err, ErrorMatches, fmt.Sprintf("unable to find remote %q", remote))
+ err = r.Clone(&CloneOptions{URL: RepositoryFixture})
+ c.Assert(err, IsNil)
- remote = ""
- _, err = r.Head(remote)
- c.Assert(err, ErrorMatches, "cannot retrieve local head: no local data found")
+ c.Assert(err, IsNil)
+ c.Assert(r.Refs(), NotNil)
}
-*/