aboutsummaryrefslogtreecommitdiffstats
path: root/repository_test.go
diff options
context:
space:
mode:
authorJoshua Sjoding <joshua.sjoding@scjalliance.com>2016-03-03 00:33:00 -0800
committerJoshua Sjoding <joshua.sjoding@scjalliance.com>2016-03-08 13:09:54 -0800
commit9e6a03b7956464ccd9d2fbacedd8e5cc23572d02 (patch)
tree0282f20de8279db354233d1d67e3743e08509020 /repository_test.go
parent9c9cdff966cc181296f400769d3c8596f17e743a (diff)
downloadgo-git-9e6a03b7956464ccd9d2fbacedd8e5cc23572d02.tar.gz
Added Object interface for Commit, Tree, Blob and Tag
* New Object interface is distinct from core.Object * New Object interface is used in places where returned object could be of any type * Object is implemented by Commit, Tree, Blob, File and Tag * Added Repository.Object function for retrieving objects of any type * Tag.Object now returns Object instead of core.Object * Tag target hash is now publicly accessible * Renamed Tag.Type field to Tag.TargetType, making it distinct from Tag.Type function * Fixed infinite recursive loop in TagIter.Close * TreeWalker.Next now returns Object instead of core.Object * Removed some duplicate test setup code
Diffstat (limited to 'repository_test.go')
-rw-r--r--repository_test.go32
1 files changed, 27 insertions, 5 deletions
diff --git a/repository_test.go b/repository_test.go
index 202c931..9e81334 100644
--- a/repository_test.go
+++ b/repository_test.go
@@ -15,8 +15,8 @@ type SuiteRepository struct {
var _ = Suite(&SuiteRepository{})
-func (s *SuiteRepository) SetUpTest(c *C) {
- s.repos = unpackFixtures(c, tagFixtures)
+func (s *SuiteRepository) SetUpSuite(c *C) {
+ s.repos = unpackFixtures(c, tagFixtures, treeWalkerFixtures)
}
func (s *SuiteRepository) TestNewRepository(c *C) {
@@ -58,6 +58,9 @@ func (s *SuiteRepository) TestCommit(c *C) {
c.Assert(err, IsNil)
c.Assert(commit.Hash.IsZero(), Equals, false)
+ c.Assert(commit.Hash, Equals, commit.ID())
+ c.Assert(commit.Hash, Equals, hash)
+ c.Assert(commit.Type(), Equals, core.CommitObject)
c.Assert(commit.Tree().Hash.IsZero(), Equals, false)
c.Assert(commit.Author.Email, Equals, "daniel@lordran.local")
}
@@ -79,6 +82,8 @@ func (s *SuiteRepository) TestCommits(c *C) {
count++
c.Assert(commit.Hash.IsZero(), Equals, false)
+ c.Assert(commit.Hash, Equals, commit.ID())
+ c.Assert(commit.Type(), Equals, core.CommitObject)
//c.Assert(commit.Tree.IsZero(), Equals, false)
}
@@ -90,10 +95,11 @@ func (s *SuiteRepository) TestTag(c *C) {
r, ok := s.repos[t.repo]
c.Assert(ok, Equals, true)
k := 0
- for hash, expected := range t.tags {
- tag, err := r.Tag(core.NewHash(hash))
+ for hashString, expected := range t.tags {
+ hash := core.NewHash(hashString)
+ tag, err := r.Tag(hash)
c.Assert(err, IsNil)
- testTagExpected(c, tag, expected, fmt.Sprintf("subtest %d, tag %d: ", i, k))
+ testTagExpected(c, tag, hash, expected, fmt.Sprintf("subtest %d, tag %d: ", i, k))
k++
}
}
@@ -107,6 +113,22 @@ func (s *SuiteRepository) TestTags(c *C) {
}
}
+func (s *SuiteRepository) TestObject(c *C) {
+ for i, t := range treeWalkerTests {
+ r, ok := s.repos[t.repo]
+ c.Assert(ok, Equals, true)
+ for k := 0; k < len(t.objs); k++ {
+ comment := fmt.Sprintf("subtest %d, tag %d", i, k)
+ info := t.objs[k]
+ hash := core.NewHash(info.Hash)
+ obj, err := r.Object(hash)
+ c.Assert(err, IsNil, Commentf(comment))
+ c.Assert(obj.Type(), Equals, info.Kind, Commentf(comment))
+ c.Assert(obj.ID(), Equals, hash, Commentf(comment))
+ }
+ }
+}
+
func (s *SuiteRepository) TestCommitIterClosePanic(c *C) {
r, err := NewRepository(RepositoryFixture, nil)
r.Remotes["origin"].upSrv = &MockGitUploadPackService{}