aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing
diff options
context:
space:
mode:
authorJavi Fontan <jfontan@gmail.com>2018-07-27 18:08:55 +0200
committerJavi Fontan <jfontan@gmail.com>2018-07-27 18:08:55 +0200
commit823abfeb3d677a74e5bb50b20cbe8cc0306e9075 (patch)
tree747ec30d754ef85ad6cca746e8eb463b965c5b4c /plumbing
parent0ade8fb60e759da42f8779b2a5c8a3f422ce4d69 (diff)
downloadgo-git-823abfeb3d677a74e5bb50b20cbe8cc0306e9075.tar.gz
plumbing/idxfile: test FindHash and writer with 64 bit offsets
Signed-off-by: Javi Fontan <jfontan@gmail.com>
Diffstat (limited to 'plumbing')
-rw-r--r--plumbing/format/idxfile/idxfile_test.go59
-rw-r--r--plumbing/format/idxfile/writer_test.go58
2 files changed, 107 insertions, 10 deletions
diff --git a/plumbing/format/idxfile/idxfile_test.go b/plumbing/format/idxfile/idxfile_test.go
index f42a419..d15accf 100644
--- a/plumbing/format/idxfile/idxfile_test.go
+++ b/plumbing/format/idxfile/idxfile_test.go
@@ -3,15 +3,22 @@ package idxfile_test
import (
"bytes"
"encoding/base64"
+ "fmt"
"io"
"testing"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/format/idxfile"
+
+ . "gopkg.in/check.v1"
+ "gopkg.in/src-d/go-git-fixtures.v3"
)
func BenchmarkFindOffset(b *testing.B) {
- idx := fixtureIndex(b)
+ idx, err := fixtureIndex()
+ if err != nil {
+ b.Fatalf(err.Error())
+ }
for i := 0; i < b.N; i++ {
for _, h := range fixtureHashes {
@@ -24,7 +31,10 @@ func BenchmarkFindOffset(b *testing.B) {
}
func BenchmarkFindCRC32(b *testing.B) {
- idx := fixtureIndex(b)
+ idx, err := fixtureIndex()
+ if err != nil {
+ b.Fatalf(err.Error())
+ }
for i := 0; i < b.N; i++ {
for _, h := range fixtureHashes {
@@ -37,7 +47,10 @@ func BenchmarkFindCRC32(b *testing.B) {
}
func BenchmarkContains(b *testing.B) {
- idx := fixtureIndex(b)
+ idx, err := fixtureIndex()
+ if err != nil {
+ b.Fatalf(err.Error())
+ }
for i := 0; i < b.N; i++ {
for _, h := range fixtureHashes {
@@ -54,7 +67,10 @@ func BenchmarkContains(b *testing.B) {
}
func BenchmarkEntries(b *testing.B) {
- idx := fixtureIndex(b)
+ idx, err := fixtureIndex()
+ if err != nil {
+ b.Fatalf(err.Error())
+ }
for i := 0; i < b.N; i++ {
iter, err := idx.Entries()
@@ -82,6 +98,23 @@ func BenchmarkEntries(b *testing.B) {
}
}
+type IndexSuite struct {
+ fixtures.Suite
+}
+
+var _ = Suite(&IndexSuite{})
+
+func (s *IndexSuite) TestFindHash(c *C) {
+ idx, err := fixtureIndex()
+ c.Assert(err, IsNil)
+
+ for i, pos := range fixtureOffsets {
+ hash, err := idx.FindHash(pos)
+ c.Assert(err, IsNil)
+ c.Assert(hash, Equals, fixtureHashes[i])
+ }
+}
+
var fixtureHashes = []plumbing.Hash{
plumbing.NewHash("303953e5aa461c203a324821bc1717f9b4fff895"),
plumbing.NewHash("5296768e3d9f661387ccbff18c4dea6c997fd78c"),
@@ -94,7 +127,19 @@ var fixtureHashes = []plumbing.Hash{
plumbing.NewHash("35858be9c6f5914cbe6768489c41eb6809a2bceb"),
}
-func fixtureIndex(t testing.TB) *idxfile.MemoryIndex {
+var fixtureOffsets = []int64{
+ 12,
+ 142,
+ 1601322837,
+ 2646996529,
+ 3452385606,
+ 3707047470,
+ 5323223332,
+ 5894072943,
+ 5924278919,
+}
+
+func fixtureIndex() (*idxfile.MemoryIndex, error) {
f := bytes.NewBufferString(fixtureLarge4GB)
idx := new(idxfile.MemoryIndex)
@@ -102,8 +147,8 @@ func fixtureIndex(t testing.TB) *idxfile.MemoryIndex {
d := idxfile.NewDecoder(base64.NewDecoder(base64.StdEncoding, f))
err := d.Decode(idx)
if err != nil {
- t.Fatalf("unexpected error decoding index: %s", err)
+ return nil, fmt.Errorf("unexpected error decoding index: %s", err)
}
- return idx
+ return idx, nil
}
diff --git a/plumbing/format/idxfile/writer_test.go b/plumbing/format/idxfile/writer_test.go
index 51273a3..780acd9 100644
--- a/plumbing/format/idxfile/writer_test.go
+++ b/plumbing/format/idxfile/writer_test.go
@@ -2,8 +2,10 @@ package idxfile_test
import (
"bytes"
+ "encoding/base64"
"io/ioutil"
+ "gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/format/idxfile"
"gopkg.in/src-d/go-git.v4/plumbing/format/packfile"
@@ -11,13 +13,13 @@ import (
"gopkg.in/src-d/go-git-fixtures.v3"
)
-type IndexSuite struct {
+type WriterSuite struct {
fixtures.Suite
}
-var _ = Suite(&IndexSuite{})
+var _ = Suite(&WriterSuite{})
-func (s *IndexSuite) TestIndexWriter(c *C) {
+func (s *WriterSuite) TestWriter(c *C) {
f := fixtures.Basic().One()
scanner := packfile.NewScanner(f.Packfile())
@@ -43,3 +45,53 @@ func (s *IndexSuite) TestIndexWriter(c *C) {
c.Assert(buf.Bytes(), DeepEquals, expected)
}
+
+func (s *WriterSuite) TestWriterLarge(c *C) {
+ writer := new(idxfile.Writer)
+ err := writer.OnHeader(uint32(len(fixture4GbEntries)))
+ c.Assert(err, IsNil)
+
+ for _, o := range fixture4GbEntries {
+ err = writer.OnInflatedObjectContent(plumbing.NewHash(o.hash), o.offset, o.crc)
+ c.Assert(err, IsNil)
+ }
+
+ err = writer.OnFooter(fixture4GbChecksum)
+ c.Assert(err, IsNil)
+
+ idx, err := writer.Index()
+ c.Assert(err, IsNil)
+
+ // load fixture index
+ f := bytes.NewBufferString(fixtureLarge4GB)
+ expected, err := ioutil.ReadAll(base64.NewDecoder(base64.StdEncoding, f))
+ c.Assert(err, IsNil)
+
+ buf := new(bytes.Buffer)
+ encoder := idxfile.NewEncoder(buf)
+ n, err := encoder.Encode(idx)
+ c.Assert(err, IsNil)
+ c.Assert(n, Equals, len(expected))
+
+ c.Assert(buf.Bytes(), DeepEquals, expected)
+}
+
+var (
+ fixture4GbChecksum = plumbing.NewHash("afabc2269205cf85da1bf7e2fdff42f73810f29b")
+
+ fixture4GbEntries = []struct {
+ offset int64
+ hash string
+ crc uint32
+ }{
+ {12, "303953e5aa461c203a324821bc1717f9b4fff895", 0xbc347c4c},
+ {142, "5296768e3d9f661387ccbff18c4dea6c997fd78c", 0xcdc22842},
+ {1601322837, "03fc8d58d44267274edef4585eaeeb445879d33f", 0x929dfaaa},
+ {2646996529, "8f3ceb4ea4cb9e4a0f751795eb41c9a4f07be772", 0xa61def8a},
+ {3452385606, "e0d1d625010087f79c9e01ad9d8f95e1628dda02", 0x06bea180},
+ {3707047470, "90eba326cdc4d1d61c5ad25224ccbf08731dd041", 0x7193f3ba},
+ {5323223332, "bab53055add7bc35882758a922c54a874d6b1272", 0xac269b8e},
+ {5894072943, "1b8995f51987d8a449ca5ea4356595102dc2fbd4", 0x2187c056},
+ {5924278919, "35858be9c6f5914cbe6768489c41eb6809a2bceb", 0x9c89d9d2},
+ }
+)