aboutsummaryrefslogtreecommitdiffstats
path: root/storage/filesystem/object_test.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2018-09-21 12:02:17 +0200
committerGitHub <noreply@github.com>2018-09-21 12:02:17 +0200
commitc2ab4ac47d87f4cd674d19228e24b6696bd1db4d (patch)
treea5797901db8d24343a73bbc7423c0ef38a61aa60 /storage/filesystem/object_test.go
parentf69f5304328165153e452382f44aa2b41df36d0f (diff)
parenta7b0102b83aa86fd299623d35666bfee93fee0c6 (diff)
downloadgo-git-c2ab4ac47d87f4cd674d19228e24b6696bd1db4d.tar.gz
Merge pull request #962 from jfontan/fix/do-not-close-files-in-iterator
storage/filesystem: keep packs open in PackfileIter
Diffstat (limited to 'storage/filesystem/object_test.go')
-rw-r--r--storage/filesystem/object_test.go44
1 files changed, 40 insertions, 4 deletions
diff --git a/storage/filesystem/object_test.go b/storage/filesystem/object_test.go
index bd4a94b..407abf2 100644
--- a/storage/filesystem/object_test.go
+++ b/storage/filesystem/object_test.go
@@ -153,18 +153,54 @@ func (s *FsSuite) TestPackfileIter(c *C) {
idxf, err := dg.ObjectPackIdx(h)
c.Assert(err, IsNil)
- iter, err := NewPackfileIter(fs, f, idxf, t)
+ iter, err := NewPackfileIter(fs, f, idxf, t, false)
c.Assert(err, IsNil)
+
err = iter.ForEach(func(o plumbing.EncodedObject) error {
c.Assert(o.Type(), Equals, t)
return nil
})
-
c.Assert(err, IsNil)
}
}
})
+}
+
+func (s *FsSuite) TestPackfileIterKeepDescriptors(c *C) {
+ fixtures.ByTag(".git").Test(c, func(f *fixtures.Fixture) {
+ fs := f.DotGit()
+ ops := dotgit.Options{KeepDescriptors: true}
+ dg := dotgit.NewWithOptions(fs, ops)
+
+ for _, t := range objectTypes {
+ ph, err := dg.ObjectPacks()
+ c.Assert(err, IsNil)
+
+ for _, h := range ph {
+ f, err := dg.ObjectPack(h)
+ c.Assert(err, IsNil)
+
+ idxf, err := dg.ObjectPackIdx(h)
+ c.Assert(err, IsNil)
+ iter, err := NewPackfileIter(fs, f, idxf, t, true)
+ c.Assert(err, IsNil)
+
+ err = iter.ForEach(func(o plumbing.EncodedObject) error {
+ c.Assert(o.Type(), Equals, t)
+ return nil
+ })
+ c.Assert(err, IsNil)
+
+ // test twice to check that packfiles are not closed
+ err = iter.ForEach(func(o plumbing.EncodedObject) error {
+ c.Assert(o.Type(), Equals, t)
+ return nil
+ })
+ c.Assert(err, IsNil)
+ }
+ }
+ })
}
func BenchmarkPackfileIter(b *testing.B) {
@@ -201,7 +237,7 @@ func BenchmarkPackfileIter(b *testing.B) {
b.Fatal(err)
}
- iter, err := NewPackfileIter(fs, f, idxf, t)
+ iter, err := NewPackfileIter(fs, f, idxf, t, false)
if err != nil {
b.Fatal(err)
}
@@ -257,7 +293,7 @@ func BenchmarkPackfileIterReadContent(b *testing.B) {
b.Fatal(err)
}
- iter, err := NewPackfileIter(fs, f, idxf, t)
+ iter, err := NewPackfileIter(fs, f, idxf, t, false)
if err != nil {
b.Fatal(err)
}