aboutsummaryrefslogtreecommitdiffstats
path: root/storage/filesystem/object_test.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2018-10-16 10:11:39 +0200
committerGitHub <noreply@github.com>2018-10-16 10:11:39 +0200
commit41d6f2c31e68a9fdcbff4a3da8c40247f1293cc9 (patch)
tree655fed8324e58a6ba44ef45f1bb2e090abe26451 /storage/filesystem/object_test.go
parent8153e040f68da6002096ef177a11510f4fb06769 (diff)
parent6faf286b97ff2e13fbdaf2c6179f8aef36b4498c (diff)
downloadgo-git-41d6f2c31e68a9fdcbff4a3da8c40247f1293cc9.tar.gz
Merge pull request #982 from keybase/strib/gh-KBFS-3474-object-sizes
tree: add a Size() method for getting plaintext size
Diffstat (limited to 'storage/filesystem/object_test.go')
-rw-r--r--storage/filesystem/object_test.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/storage/filesystem/object_test.go b/storage/filesystem/object_test.go
index 407abf2..4e6bbfb 100644
--- a/storage/filesystem/object_test.go
+++ b/storage/filesystem/object_test.go
@@ -83,6 +83,44 @@ func (s *FsSuite) TestGetFromPackfileKeepDescriptors(c *C) {
})
}
+func (s *FsSuite) TestGetSizeOfObjectFile(c *C) {
+ fs := fixtures.ByTag(".git").ByTag("unpacked").One().DotGit()
+ o := NewObjectStorage(dotgit.New(fs), cache.NewObjectLRUDefault())
+
+ // Get the size of `tree_walker.go`.
+ expected := plumbing.NewHash("cbd81c47be12341eb1185b379d1c82675aeded6a")
+ size, err := o.EncodedObjectSize(expected)
+ c.Assert(err, IsNil)
+ c.Assert(size, Equals, int64(2412))
+}
+
+func (s *FsSuite) TestGetSizeFromPackfile(c *C) {
+ fixtures.Basic().ByTag(".git").Test(c, func(f *fixtures.Fixture) {
+ fs := f.DotGit()
+ o := NewObjectStorage(dotgit.New(fs), cache.NewObjectLRUDefault())
+
+ // Get the size of `binary.jpg`.
+ expected := plumbing.NewHash("d5c0f4ab811897cadf03aec358ae60d21f91c50d")
+ size, err := o.EncodedObjectSize(expected)
+ c.Assert(err, IsNil)
+ c.Assert(size, Equals, int64(76110))
+ })
+}
+
+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())