aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plumbing/object/tree_test.go37
1 files changed, 37 insertions, 0 deletions
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