aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/idxfile/writer_test.go
diff options
context:
space:
mode:
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)
+}