aboutsummaryrefslogtreecommitdiffstats
path: root/formats/idxfile/encoder_test.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-09-08 23:58:41 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2016-09-08 23:58:41 +0200
commit3b1baea2dd9353f42b3a9d93f6bc92ecbe9f4f01 (patch)
treed255b7e6edbcbaba1f98cf0c666a82c0f9750019 /formats/idxfile/encoder_test.go
parent2293a3dbda0a96f5cbac851bb73e1e675417e4f3 (diff)
downloadgo-git-3b1baea2dd9353f42b3a9d93f6bc92ecbe9f4f01.tar.gz
format: packfile based on ObjectStorage and CRC32 calculation
Diffstat (limited to 'formats/idxfile/encoder_test.go')
-rw-r--r--formats/idxfile/encoder_test.go52
1 files changed, 19 insertions, 33 deletions
diff --git a/formats/idxfile/encoder_test.go b/formats/idxfile/encoder_test.go
index bfb9f91..11ecaee 100644
--- a/formats/idxfile/encoder_test.go
+++ b/formats/idxfile/encoder_test.go
@@ -2,46 +2,32 @@ package idxfile
import (
"bytes"
- "io"
- "os"
+ "io/ioutil"
. "gopkg.in/check.v1"
+ "gopkg.in/src-d/go-git.v4/fixtures"
)
-func (s *IdxfileSuite) TestEncode(c *C) {
- for i, path := range [...]string{
- "fixtures/git-fixture.idx",
- "../packfile/fixtures/spinnaker-spinnaker.idx",
- } {
- com := Commentf("subtest %d: path = %s", i, path)
-
- exp, idx, err := decode(path)
- c.Assert(err, IsNil, com)
-
- obt := new(bytes.Buffer)
- e := NewEncoder(obt)
- size, err := e.Encode(idx)
- c.Assert(err, IsNil, com)
-
- c.Assert(size, Equals, exp.Len(), com)
- c.Assert(obt, DeepEquals, exp, com)
- }
+func (s *IdxfileSuite) SetUpSuite(c *C) {
+ fixtures.RootFolder = "../../fixtures"
}
-func decode(path string) (*bytes.Buffer, *Idxfile, error) {
- f, err := os.Open(path)
- if err != nil {
- return nil, nil, err
- }
+func (s *IdxfileSuite) TestEncode(c *C) {
+ fixtures.All().Test(c, func(f *fixtures.Fixture) {
+ expected, err := ioutil.ReadAll(f.Idx())
+ c.Assert(err, IsNil)
- cont := new(bytes.Buffer)
- tee := io.TeeReader(f, cont)
+ idx := &Idxfile{}
+ d := NewDecoder(bytes.NewBuffer(expected))
+ err = d.Decode(idx)
+ c.Assert(err, IsNil)
- d := NewDecoder(tee)
- idx := &Idxfile{}
- if err = d.Decode(idx); err != nil {
- return nil, nil, err
- }
+ result := bytes.NewBuffer(nil)
+ e := NewEncoder(result)
+ size, err := e.Encode(idx)
+ c.Assert(err, IsNil)
- return cont, idx, f.Close()
+ c.Assert(size, Equals, len(expected))
+ c.Assert(result.Bytes(), DeepEquals, expected)
+ })
}