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