aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/idxfile/writer_test.go
diff options
context:
space:
mode:
authorJavi Fontan <jfontan@gmail.com>2018-07-26 14:19:32 +0200
committerGitHub <noreply@github.com>2018-07-26 14:19:32 +0200
commita08061aa298ec4b92bbe470a1834465f25a0ad0d (patch)
tree8804820221e05096433b2e0cef5249e4a3e94c7b /plumbing/format/idxfile/writer_test.go
parenta8ff3e599b3ee998a8b8626cd9fe9fa68490d354 (diff)
parent79f249465b24104b73c9dc220d9098cecdab4d77 (diff)
downloadgo-git-a08061aa298ec4b92bbe470a1834465f25a0ad0d.tar.gz
Merge pull request #898 from jfontan/feature/new-packfile-parser
Feature/new packfile parser
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..51273a3
--- /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.Index()
+ 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)
+}