aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/idxfile/writer_test.go
diff options
context:
space:
mode:
authorJavi Fontan <jfontan@gmail.com>2018-07-20 13:01:27 +0200
committerJavi Fontan <jfontan@gmail.com>2018-07-26 14:17:56 +0200
commit65e8359db00ae79838d19e19f69594f6a262c3d4 (patch)
tree6fd7c2a50b7fe914499a5f46911901547f3bb77c /plumbing/format/idxfile/writer_test.go
parent4e3765aef344eae2fbcd977fefd66b6571638d59 (diff)
downloadgo-git-65e8359db00ae79838d19e19f69594f6a262c3d4.tar.gz
plumbing/idxfile: support offset64 generating indexes
Signed-off-by: Javi Fontan <jfontan@gmail.com>
Diffstat (limited to 'plumbing/format/idxfile/writer_test.go')
-rw-r--r--plumbing/format/idxfile/writer_test.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/plumbing/format/idxfile/writer_test.go b/plumbing/format/idxfile/writer_test.go
new file mode 100644
index 0000000..92d2046
--- /dev/null
+++ b/plumbing/format/idxfile/writer_test.go
@@ -0,0 +1,45 @@
+package idxfile_test
+
+import (
+ "bytes"
+ "io/ioutil"
+
+ "gopkg.in/src-d/go-git.v4/plumbing/format/idxfile"
+ "gopkg.in/src-d/go-git.v4/plumbing/format/packfile"
+
+ . "gopkg.in/check.v1"
+ "gopkg.in/src-d/go-git-fixtures.v3"
+)
+
+type IndexSuite struct {
+ fixtures.Suite
+}
+
+var _ = Suite(&IndexSuite{})
+
+func (s *IndexSuite) TestIndexWriter(c *C) {
+ f := fixtures.Basic().One()
+ scanner := packfile.NewScanner(f.Packfile())
+
+ obs := new(idxfile.Writer)
+ parser := packfile.NewParser(scanner, obs)
+
+ _, err := parser.Parse()
+ c.Assert(err, IsNil)
+
+ idx, err := obs.CreateIndex()
+ c.Assert(err, IsNil)
+
+ idxFile := f.Idx()
+ expected, err := ioutil.ReadAll(idxFile)
+ c.Assert(err, IsNil)
+ idxFile.Close()
+
+ 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)
+}