aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/object/tree_test.go
diff options
context:
space:
mode:
authorAlberto Cortés <alcortesm@gmail.com>2017-01-26 14:21:01 +0100
committerGitHub <noreply@github.com>2017-01-26 14:21:01 +0100
commit1c2602a791371e76d52f89b2c8193cb200c66ad6 (patch)
treedcefc9d45f91de1450d41bdc415b1056a637f2c6 /plumbing/object/tree_test.go
parentec28bd3808d42f523eeb05e23909dbfc54eb9bcd (diff)
downloadgo-git-1c2602a791371e76d52f89b2c8193cb200c66ad6.tar.gz
adds Tree method to Tree (#224)
This patch adds a new method to the Tree object that allows you to get a child tree from a parent tree by its relative name. Before this patch, this was only possible with files, using the File method. The new Tree method has a similar signature to the old File method for consistency.
Diffstat (limited to 'plumbing/object/tree_test.go')
-rw-r--r--plumbing/object/tree_test.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/plumbing/object/tree_test.go b/plumbing/object/tree_test.go
index 00601c1..9b9614b 100644
--- a/plumbing/object/tree_test.go
+++ b/plumbing/object/tree_test.go
@@ -48,6 +48,31 @@ func (s *TreeSuite) TestType(c *C) {
c.Assert(s.Tree.Type(), Equals, plumbing.TreeObject)
}
+func (s *TreeSuite) TestTree(c *C) {
+ expectedEntry, ok := s.Tree.m["vendor"]
+ c.Assert(ok, Equals, true)
+ expected := expectedEntry.Hash
+
+ obtainedTree, err := s.Tree.Tree("vendor")
+ c.Assert(err, IsNil)
+ c.Assert(obtainedTree.Hash, Equals, expected)
+}
+
+func (s *TreeSuite) TestTreeNotFound(c *C) {
+ d, err := s.Tree.Tree("not-found")
+ c.Assert(d, IsNil)
+ c.Assert(err, Equals, ErrDirectoryNotFound)
+}
+
+func (s *TreeSuite) TestTreeFailsWithExistingFiles(c *C) {
+ _, err := s.Tree.File("LICENSE")
+ c.Assert(err, IsNil)
+
+ d, err := s.Tree.Tree("LICENSE")
+ c.Assert(d, IsNil)
+ c.Assert(err, Equals, ErrDirectoryNotFound)
+}
+
func (s *TreeSuite) TestFile(c *C) {
f, err := s.Tree.File("LICENSE")
c.Assert(err, IsNil)
@@ -60,6 +85,15 @@ func (s *TreeSuite) TestFileNotFound(c *C) {
c.Assert(err, Equals, ErrFileNotFound)
}
+func (s *TreeSuite) TestFileFailsWithExistingTrees(c *C) {
+ _, err := s.Tree.Tree("vendor")
+ c.Assert(err, IsNil)
+
+ f, err := s.Tree.File("vendor")
+ c.Assert(f, IsNil)
+ c.Assert(err, Equals, ErrFileNotFound)
+}
+
func (s *TreeSuite) TestFiles(c *C) {
var count int
err := s.Tree.Files().ForEach(func(f *File) error {