From 1c2602a791371e76d52f89b2c8193cb200c66ad6 Mon Sep 17 00:00:00 2001 From: Alberto Cortés Date: Thu, 26 Jan 2017 14:21:01 +0100 Subject: 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. --- plumbing/object/tree_test.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'plumbing/object/tree_test.go') 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 { -- cgit