Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 8176f08

Browse files
committed
storage/filesystem: compare files using offset in test
Using equals to compare files it uses diff to do so. This can potentially consume lots of ram. Changed the comparison to use file offsets. If the descriptor is reused the offset is maintained. Signed-off-by: Javi Fontan <jfontan@gmail.com>
1 parent 9013dde commit 8176f08

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

storage/filesystem/dotgit/dotgit_test.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,16 +474,27 @@ func (s *SuiteDotGit) TestObjectPackWithKeepDescriptors(c *C) {
474474
c.Assert(err, IsNil)
475475
c.Assert(filepath.Ext(pack.Name()), Equals, ".pack")
476476

477+
// Move to an specific offset
478+
pack.Seek(42, os.SEEK_SET)
479+
477480
pack2, err := dir.ObjectPack(f.PackfileHash)
478481
c.Assert(err, IsNil)
479-
c.Assert(pack, Equals, pack2)
482+
483+
// If the file is the same the offset should be the same
484+
offset, err := pack2.Seek(0, os.SEEK_CUR)
485+
c.Assert(err, IsNil)
486+
c.Assert(offset, Equals, int64(42))
480487

481488
err = dir.Close()
482489
c.Assert(err, IsNil)
483490

484491
pack2, err = dir.ObjectPack(f.PackfileHash)
485492
c.Assert(err, IsNil)
486-
c.Assert(pack, Not(Equals), pack2)
493+
494+
// If the file is opened again its offset should be 0
495+
offset, err = pack2.Seek(0, os.SEEK_CUR)
496+
c.Assert(err, IsNil)
497+
c.Assert(offset, Equals, int64(0))
487498

488499
err = pack2.Close()
489500
c.Assert(err, IsNil)

storage/filesystem/object_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package filesystem
22

33
import (
44
"io/ioutil"
5+
"os"
56
"testing"
67

78
"gopkg.in/src-d/go-git.v4/plumbing"
@@ -66,12 +67,17 @@ func (s *FsSuite) TestGetFromPackfileKeepDescriptors(c *C) {
6667
pack1, err := dg.ObjectPack(packfiles[0])
6768
c.Assert(err, IsNil)
6869

70+
pack1.Seek(42, os.SEEK_SET)
71+
6972
err = o.Close()
7073
c.Assert(err, IsNil)
7174

7275
pack2, err := dg.ObjectPack(packfiles[0])
7376
c.Assert(err, IsNil)
74-
c.Assert(pack1, Not(Equals), pack2)
77+
78+
offset, err := pack2.Seek(0, os.SEEK_CUR)
79+
c.Assert(err, IsNil)
80+
c.Assert(offset, Equals, int64(0))
7581

7682
err = o.Close()
7783
c.Assert(err, IsNil)

0 commit comments

Comments
 (0)