aboutsummaryrefslogtreecommitdiffstats
path: root/file_test.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-08-22 03:29:05 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2016-08-22 03:29:05 +0200
commit2ed3474ab8e52c98a87e390d5128d45d693a115d (patch)
tree6f136c2508c22f6b5146ef08c49821a45a5f2357 /file_test.go
parent5b13c1a2e55cb442484d9c7b45389f422b110eec (diff)
downloadgo-git-2ed3474ab8e52c98a87e390d5128d45d693a115d.tar.gz
ForEach review and Commit.Tree err return
Diffstat (limited to 'file_test.go')
-rw-r--r--file_test.go46
1 files changed, 44 insertions, 2 deletions
diff --git a/file_test.go b/file_test.go
index e702ce7..e49970a 100644
--- a/file_test.go
+++ b/file_test.go
@@ -9,6 +9,7 @@ import (
)
type SuiteFile struct {
+ BaseSuite
repos map[string]*Repository
}
@@ -53,7 +54,10 @@ func (s *SuiteFile) TestIter(c *C) {
commit, err := r.Commit(core.NewHash(t.commit))
c.Assert(err, IsNil, Commentf("subtest %d: %v (%s)", i, err, t.commit))
- iter := NewFileIter(r, commit.Tree())
+ tree, err := commit.Tree()
+ c.Assert(err, IsNil)
+
+ iter := NewFileIter(r, tree)
for k := 0; k < len(t.files); k++ {
exp := t.files[k]
file, err := iter.Next()
@@ -186,7 +190,10 @@ func (s *SuiteFile) TestIgnoreEmptyDirEntries(c *C) {
commit, err := s.repos[t.repo].Commit(core.NewHash(t.commit))
c.Assert(err, IsNil, Commentf("subtest %d: %v (%s)", i, err, t.commit))
- iter := commit.Tree().Files()
+ tree, err := commit.Tree()
+ c.Assert(err, IsNil)
+
+ iter := tree.Files()
defer iter.Close()
for file, err := iter.Next(); err == nil; file, err = iter.Next() {
_, _ = file.Contents()
@@ -194,3 +201,38 @@ func (s *SuiteFile) TestIgnoreEmptyDirEntries(c *C) {
}
}
}
+
+func (s *SuiteFile) TestFileIter(c *C) {
+ hash := core.NewHash("1669dce138d9b841a518c64b10914d88f5e488ea")
+
+ commit, err := s.Repository.Commit(hash)
+ c.Assert(err, IsNil)
+
+ tree, err := commit.Tree()
+
+ expected := []string{
+ ".gitignore",
+ "CHANGELOG",
+ "LICENSE",
+ "binary.jpg",
+ }
+
+ var count int
+ i := tree.Files()
+ i.ForEach(func(f *File) error {
+ c.Assert(f.Name, Equals, expected[count])
+ count++
+ return nil
+ })
+
+ c.Assert(count, Equals, 4)
+
+ count = 0
+ i = tree.Files()
+ i.ForEach(func(f *File) error {
+ count++
+ return core.ErrStop
+ })
+
+ c.Assert(count, Equals, 1)
+}