diff options
author | Ori Rawlings <orirawlings@gmail.com> | 2017-11-22 08:51:48 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-22 08:51:48 -0500 |
commit | d9518b57cdc9701c0077d23db54558f496daea9f (patch) | |
tree | 26b5b11c236144ca68801f30de07627482d08e01 /plumbing | |
parent | b08cc8dc5450981530af3e6f6ad1159ae8ea8705 (diff) | |
parent | 458b90ec958fcfe4246be87ef85aad215c24256d (diff) | |
download | go-git-d9518b57cdc9701c0077d23db54558f496daea9f.tar.gz |
Merge pull request #652 from ferhatelmas/err-return-on-tree-decode
plumbing/object: do not eat error on tree decode
Diffstat (limited to 'plumbing')
-rw-r--r-- | plumbing/object/tree.go | 4 | ||||
-rw-r--r-- | plumbing/object/tree_test.go | 37 |
2 files changed, 39 insertions, 2 deletions
diff --git a/plumbing/object/tree.go b/plumbing/object/tree.go index 44ac720..2fcd979 100644 --- a/plumbing/object/tree.go +++ b/plumbing/object/tree.go @@ -136,9 +136,9 @@ func (t *Tree) dir(baseName string) (*Tree, error) { } tree := &Tree{s: t.s} - tree.Decode(obj) + err = tree.Decode(obj) - return tree, nil + return tree, err } var errEntryNotFound = errors.New("entry not found") diff --git a/plumbing/object/tree_test.go b/plumbing/object/tree_test.go index 796d979..6d3907e 100644 --- a/plumbing/object/tree_test.go +++ b/plumbing/object/tree_test.go @@ -1,6 +1,7 @@ package object import ( + "errors" "io" "gopkg.in/src-d/go-git.v4/plumbing" @@ -113,6 +114,42 @@ func (s *TreeSuite) TestFindEntry(c *C) { c.Assert(e.Name, Equals, "foo.go") } +// Overrides returned plumbing.EncodedObject for given hash. +// Otherwise, delegates to actual storer to get real object +type fakeStorer struct { + storer.EncodedObjectStorer + hash plumbing.Hash + fake fakeEncodedObject +} + +func (fs fakeStorer) EncodedObject(t plumbing.ObjectType, h plumbing.Hash) (plumbing.EncodedObject, error) { + if fs.hash == h { + return fs.fake, nil + } + return fs.EncodedObjectStorer.EncodedObject(t, h) +} + +// Overrides reader of plumbing.EncodedObject to simulate read error +type fakeEncodedObject struct{ plumbing.EncodedObject } + +func (fe fakeEncodedObject) Reader() (io.ReadCloser, error) { + return nil, errors.New("Simulate encoded object can't be read") +} + +func (s *TreeSuite) TestDir(c *C) { + vendor, err := s.Tree.dir("vendor") + c.Assert(err, IsNil) + + t, err := GetTree(s.Tree.s, s.Tree.ID()) + c.Assert(err, IsNil) + o, err := t.s.EncodedObject(plumbing.AnyObject, vendor.ID()) + c.Assert(err, IsNil) + + t.s = fakeStorer{t.s, vendor.ID(), fakeEncodedObject{o}} + _, err = t.dir("vendor") + c.Assert(err, NotNil) +} + // This plumbing.EncodedObject implementation has a reader that only returns 6 // bytes at a time, this should simulate the conditions when a read // returns less bytes than asked, for example when reading a hash which |