aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntonio Navarro Perez <antnavper@gmail.com>2016-12-15 13:46:08 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2016-12-15 13:46:08 +0100
commitc49d8e374443180ff68404c904ccad5d87f9073e (patch)
tree20cc511d3a6a60b657c3ea1c3783254537102d54
parent249c4137f4f34992c9bb6a60954e30a27994add7 (diff)
downloadgo-git-c49d8e374443180ff68404c904ccad5d87f9073e.tar.gz
Improve Tag test coverage. (#188)
-rw-r--r--plumbing/object/tag.go6
-rw-r--r--plumbing/object/tag_test.go112
2 files changed, 109 insertions, 9 deletions
diff --git a/plumbing/object/tag.go b/plumbing/object/tag.go
index 5ca363d..f747ca0 100644
--- a/plumbing/object/tag.go
+++ b/plumbing/object/tag.go
@@ -260,9 +260,7 @@ func objectAsString(obj Object) string {
switch o := obj.(type) {
case *Commit:
return o.String()
- case *Tag:
- return o.String()
+ default:
+ return ""
}
-
- return ""
}
diff --git a/plumbing/object/tag_test.go b/plumbing/object/tag_test.go
index 2721442..2b63115 100644
--- a/plumbing/object/tag_test.go
+++ b/plumbing/object/tag_test.go
@@ -2,11 +2,13 @@ package object
import (
"fmt"
+ "io"
"time"
"gopkg.in/src-d/go-git.v4/fixtures"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/storage/filesystem"
+ "gopkg.in/src-d/go-git.v4/storage/memory"
. "gopkg.in/check.v1"
)
@@ -19,14 +21,18 @@ var _ = Suite(&TagSuite{})
func (s *TagSuite) SetUpSuite(c *C) {
s.BaseObjectsSuite.SetUpSuite(c)
- storer, err := filesystem.NewStorage(fixtures.ByURL("https://github.com/git-fixtures/tags.git").One().DotGit())
+ storer, err := filesystem.NewStorage(
+ fixtures.ByURL("https://github.com/git-fixtures/tags.git").One().DotGit())
c.Assert(err, IsNil)
s.Storer = storer
}
-func (s *TagSuite) TestName(c *C) {
- tag := s.tag(c, plumbing.NewHash("b742a2a9fa0afcfa9a6fad080980fbc26b007c69"))
+func (s *TagSuite) TestNameIDAndType(c *C) {
+ h := plumbing.NewHash("b742a2a9fa0afcfa9a6fad080980fbc26b007c69")
+ tag := s.tag(c, h)
c.Assert(tag.Name, Equals, "annotated-tag")
+ c.Assert(h, Equals, tag.ID())
+ c.Assert(plumbing.TagObject, Equals, tag.Type())
}
func (s *TagSuite) TestTagger(c *C) {
@@ -44,6 +50,15 @@ func (s *TagSuite) TestAnnotated(c *C) {
c.Assert(commit.ID().String(), Equals, "f7b877701fbf855b44c0a9e86f3fdce2c298b07f")
}
+func (s *TagSuite) TestCommitError(c *C) {
+ tag := s.tag(c, plumbing.NewHash("fe6cb94756faa81e5ed9240f9191b833db5f40ae"))
+
+ commit, err := tag.Commit()
+ c.Assert(commit, IsNil)
+ c.Assert(err, NotNil)
+ c.Assert(err, Equals, ErrUnsupportedObject)
+}
+
func (s *TagSuite) TestCommit(c *C) {
tag := s.tag(c, plumbing.NewHash("ad7897c0fb8e7d9a9ba41fa66072cf06095a6cfc"))
c.Assert(tag.Message, Equals, "a tagged commit\n")
@@ -54,6 +69,15 @@ func (s *TagSuite) TestCommit(c *C) {
c.Assert(commit.ID().String(), Equals, "f7b877701fbf855b44c0a9e86f3fdce2c298b07f")
}
+func (s *TagSuite) TestBlobError(c *C) {
+ tag := s.tag(c, plumbing.NewHash("ad7897c0fb8e7d9a9ba41fa66072cf06095a6cfc"))
+
+ commit, err := tag.Blob()
+ c.Assert(commit, IsNil)
+ c.Assert(err, NotNil)
+ c.Assert(err, Equals, ErrUnsupportedObject)
+}
+
func (s *TagSuite) TestBlob(c *C) {
tag := s.tag(c, plumbing.NewHash("fe6cb94756faa81e5ed9240f9191b833db5f40ae"))
c.Assert(tag.Message, Equals, "a tagged blob\n")
@@ -64,6 +88,15 @@ func (s *TagSuite) TestBlob(c *C) {
c.Assert(blob.ID().String(), Equals, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391")
}
+func (s *TagSuite) TestTreeError(c *C) {
+ tag := s.tag(c, plumbing.NewHash("fe6cb94756faa81e5ed9240f9191b833db5f40ae"))
+
+ tree, err := tag.Tree()
+ c.Assert(tree, IsNil)
+ c.Assert(err, NotNil)
+ c.Assert(err, Equals, ErrUnsupportedObject)
+}
+
func (s *TagSuite) TestTree(c *C) {
tag := s.tag(c, plumbing.NewHash("152175bf7e5580299fa1f0ba41ef6474cc043b70"))
c.Assert(tag.Message, Equals, "a tagged tree\n")
@@ -99,25 +132,47 @@ func (s *TagSuite) TestTagItter(c *C) {
var count int
i := NewTagIter(s.Storer, iter)
+ tag, err := i.Next()
+ c.Assert(err, IsNil)
+ c.Assert(tag, NotNil)
+ c.Assert(tag.Type(), Equals, plumbing.TagObject)
+
err = i.ForEach(func(t *Tag) error {
+ c.Assert(t, NotNil)
+ c.Assert(t.Type(), Equals, plumbing.TagObject)
count++
+
return nil
})
c.Assert(err, IsNil)
- c.Assert(count, Equals, 4)
+ c.Assert(count, Equals, 3)
+
+ tag, err = i.Next()
+ c.Assert(err, Equals, io.EOF)
+ c.Assert(tag, IsNil)
}
func (s *TagSuite) TestTagIterError(c *C) {
iter, err := s.Storer.IterEncodedObjects(plumbing.TagObject)
c.Assert(err, IsNil)
+ randomErr := fmt.Errorf("a random error")
i := NewTagIter(s.Storer, iter)
err = i.ForEach(func(t *Tag) error {
- return fmt.Errorf("a random error")
+ return randomErr
})
c.Assert(err, NotNil)
+ c.Assert(err, Equals, randomErr)
+}
+
+func (s *TagSuite) TestTagDecodeWrongType(c *C) {
+ newTag := &Tag{}
+ obj := &plumbing.MemoryObject{}
+ obj.SetType(plumbing.BlobObject)
+ err := newTag.Decode(obj)
+ c.Assert(err, Equals, ErrUnsupportedObject)
}
func (s *TagSuite) TestTagEncodeDecodeIdempotent(c *C) {
@@ -166,4 +221,51 @@ func (s *TagSuite) TestString(c *C) {
" initial\n"+
"\n",
)
+
+ tag = s.tag(c, plumbing.NewHash("152175bf7e5580299fa1f0ba41ef6474cc043b70"))
+ c.Assert(tag.String(), Equals, ""+
+ "tag tree-tag\n"+
+ "Tagger: Máximo Cuadros <mcuadros@gmail.com>\n"+
+ "Date: Wed Sep 21 21:17:56 2016 +0200\n"+
+ "\n"+
+ "a tagged tree\n"+
+ "\n",
+ )
+}
+
+func (s *TagSuite) TestTagToTagString(c *C) {
+ store := memory.NewStorage()
+
+ tagOneHash := plumbing.NewHash("TAGONE")
+ tagTwoHash := plumbing.NewHash("TAGTWO")
+
+ tagOne := &Tag{
+ Target: tagTwoHash,
+ Hash: tagOneHash,
+ Name: "TAG ONE",
+ TargetType: plumbing.TagObject,
+ }
+ tagTwo := &Tag{
+ Target: tagOneHash,
+ Hash: tagTwoHash,
+ Name: "TAG TWO",
+ TargetType: plumbing.TagObject,
+ }
+ oOne := &plumbing.MemoryObject{}
+ tagOne.Encode(oOne)
+ oTwo := &plumbing.MemoryObject{}
+ tagTwo.Encode(oTwo)
+
+ store.SetEncodedObject(oOne)
+ store.SetEncodedObject(oTwo)
+
+ tag, err := GetTag(store, tagOneHash)
+ c.Assert(err, IsNil)
+
+ c.Assert(tag.String(), Equals,
+ "tag TAG TWO\n"+
+ "Tagger: <>\n"+
+ "Date: Mon Jan 01 00:00:00 0001 +0000\n"+
+ "\n"+
+ "\n")
}