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 /tree_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 'tree_test.go')
-rw-r--r-- | tree_test.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tree_test.go b/tree_test.go index cf1ebdd..5f285af 100644 --- a/tree_test.go +++ b/tree_test.go @@ -2,6 +2,7 @@ package git import ( "io" + "os" "gopkg.in/src-d/go-git.v4/core" @@ -1254,6 +1255,28 @@ func (s *SuiteTree) TestTreeDecodeReadBug(c *C) { c.Assert(EntriesEquals(obtained.Entries, expected.Entries), Equals, true) } +func (s *SuiteTree) TestTreeDecodeEncodeIdempotent(c *C) { + trees := []*Tree{ + &Tree{ + Entries: []TreeEntry{ + TreeEntry{"foo", os.FileMode(0), core.NewHash("b029517f6300c2da0f4b651b8642506cd6aaf45d")}, + TreeEntry{"bar", os.FileMode(0), core.NewHash("c029517f6300c2da0f4b651b8642506cd6aaf45d")}, + TreeEntry{"baz", os.FileMode(0), core.NewHash("d029517f6300c2da0f4b651b8642506cd6aaf45d")}, + }, + }, + } + for _, tree := range trees { + obj := &core.MemoryObject{} + err := tree.Encode(obj) + c.Assert(err, IsNil) + newTree := &Tree{} + err = newTree.Decode(obj) + c.Assert(err, IsNil) + tree.Hash = obj.Hash() + c.Assert(newTree, DeepEquals, tree) + } +} + func EntriesEquals(a, b []TreeEntry) bool { if a == nil && b == nil { return true |