diff options
author | Jeremy Stribling <strib@alum.mit.edu> | 2018-10-12 13:00:37 -0700 |
---|---|---|
committer | Jeremy Stribling <strib@alum.mit.edu> | 2018-10-12 13:03:19 -0700 |
commit | b3a3f0ab953608fb283392d4431a963622643b4c (patch) | |
tree | 90e71cb643748562b93c0b93c5d2088b48b52010 /storage/filesystem | |
parent | 5c471c34813577a420c1a5af61dd855f70badce1 (diff) | |
download | go-git-b3a3f0ab953608fb283392d4431a963622643b4c.tar.gz |
filesystem: add a new test for EncodedObjectSize
Suggested by taruti.
Signed-off-by: Jeremy Stribling <strib@alum.mit.edu>
Diffstat (limited to 'storage/filesystem')
-rw-r--r-- | storage/filesystem/object.go | 4 | ||||
-rw-r--r-- | storage/filesystem/object_test.go | 14 |
2 files changed, 15 insertions, 3 deletions
diff --git a/storage/filesystem/object.go b/storage/filesystem/object.go index d2ba411..6cd2d4c 100644 --- a/storage/filesystem/object.go +++ b/storage/filesystem/object.go @@ -205,9 +205,7 @@ func (s *ObjectStorage) encodedObjectSizeFromPackfile(h plumbing.Hash) ( if ok { return obj.Size(), nil } - } - - if err != nil && err != plumbing.ErrObjectNotFound { + } else if err != nil && err != plumbing.ErrObjectNotFound { return 0, err } diff --git a/storage/filesystem/object_test.go b/storage/filesystem/object_test.go index 3a0cc4f..4e6bbfb 100644 --- a/storage/filesystem/object_test.go +++ b/storage/filesystem/object_test.go @@ -107,6 +107,20 @@ func (s *FsSuite) TestGetSizeFromPackfile(c *C) { }) } +func (s *FsSuite) TestGetSizeOfAllObjectFiles(c *C) { + fs := fixtures.ByTag(".git").One().DotGit() + o := NewObjectStorage(dotgit.New(fs), cache.NewObjectLRUDefault()) + + // Get the size of `tree_walker.go`. + err := o.ForEachObjectHash(func(h plumbing.Hash) error { + size, err := o.EncodedObjectSize(h) + c.Assert(err, IsNil) + c.Assert(size, Not(Equals), int64(0)) + return nil + }) + c.Assert(err, IsNil) +} + func (s *FsSuite) TestGetFromPackfileMultiplePackfiles(c *C) { fs := fixtures.ByTag(".git").ByTag("multi-packfile").One().DotGit() o := NewObjectStorage(dotgit.New(fs), cache.NewObjectLRUDefault()) |