diff options
author | Santiago M. Mola <santi@mola.io> | 2016-08-29 22:39:08 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-08-29 22:39:08 +0200 |
commit | 5cf20a4edf7803458a1c2ec94e902369bed76f28 (patch) | |
tree | b6a0276ab12f82383818892064038fb0b79e161b /tag_test.go | |
parent | a97ca42cbce377b5725ecc41e4539fc7e263b90d (diff) | |
download | go-git-5cf20a4edf7803458a1c2ec94e902369bed76f28.tar.gz |
object: Add Encode method to all objects. (#70)
Encode method encodes a typed object (commit, tree,
tag, blob) into raw core.Object representation.
Additionally, Decode does not trim commit message
lines. This is needed for Decode/Encode to be
idempotent.
Diffstat (limited to 'tag_test.go')
-rw-r--r-- | tag_test.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tag_test.go b/tag_test.go index a66cac1..ac4763b 100644 --- a/tag_test.go +++ b/tag_test.go @@ -139,6 +139,36 @@ func (s *SuiteTag) TestObject(c *C) { } } +func (s *SuiteTag) TestTagEncodeDecodeIdempotent(c *C) { + ts, err := time.Parse(time.RFC3339, "2006-01-02T15:04:05-07:00") + c.Assert(err, IsNil) + tags := []*Tag{ + &Tag{ + Name: "foo", + Tagger: Signature{Name: "Foo", Email: "foo@example.local", When: ts}, + Message: "Message\n\nFoo\nBar\nBaz\n\n", + TargetType: core.BlobObject, + Target: core.NewHash("b029517f6300c2da0f4b651b8642506cd6aaf45d"), + }, + &Tag{ + Name: "foo", + Tagger: Signature{Name: "Foo", Email: "foo@example.local", When: ts}, + TargetType: core.BlobObject, + Target: core.NewHash("b029517f6300c2da0f4b651b8642506cd6aaf45d"), + }, + } + for _, tag := range tags { + obj := &core.MemoryObject{} + err = tag.Encode(obj) + c.Assert(err, IsNil) + newTag := &Tag{} + err = newTag.Decode(obj) + c.Assert(err, IsNil) + tag.Hash = obj.Hash() + c.Assert(newTag, DeepEquals, tag) + } +} + func testTagExpected(c *C, tag *Tag, hash core.Hash, exp expectedTag, com string) { when, err := time.Parse(time.RFC3339, exp.When) c.Assert(err, IsNil) |