diff options
Diffstat (limited to 'plumbing/format/packfile')
-rw-r--r-- | plumbing/format/packfile/packfile_test.go | 42 | ||||
-rw-r--r-- | plumbing/format/packfile/parser_test.go | 28 |
2 files changed, 29 insertions, 41 deletions
diff --git a/plumbing/format/packfile/packfile_test.go b/plumbing/format/packfile/packfile_test.go index 8b1b934..60c7c73 100644 --- a/plumbing/format/packfile/packfile_test.go +++ b/plumbing/format/packfile/packfile_test.go @@ -4,7 +4,6 @@ import ( "io" "math" - "github.com/go-git/go-billy/v5/osfs" fixtures "github.com/go-git/go-git-fixtures/v4" "github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing/format/idxfile" @@ -109,14 +108,10 @@ var expectedEntries = map[plumbing.Hash]int64{ func (s *PackfileSuite) SetUpTest(c *C) { s.f = fixtures.Basic().One() - fs := osfs.New("") - f, err := fs.Open(s.f.Packfile().Name()) - c.Assert(err, IsNil) - s.idx = idxfile.NewMemoryIndex() c.Assert(idxfile.NewDecoder(s.f.Idx()).Decode(s.idx), IsNil) - s.p = packfile.NewPackfile(s.idx, fs, f) + s.p = packfile.NewPackfile(s.idx, fixtures.Filesystem, s.f.Packfile()) } func (s *PackfileSuite) TearDownTest(c *C) { @@ -126,11 +121,8 @@ func (s *PackfileSuite) TearDownTest(c *C) { func (s *PackfileSuite) TestDecode(c *C) { fixtures.Basic().ByTag("packfile").Test(c, func(f *fixtures.Fixture) { index := getIndexFromIdxFile(f.Idx()) - fs := osfs.New("") - pf, err := fs.Open(f.Packfile().Name()) - c.Assert(err, IsNil) - p := packfile.NewPackfile(index, fs, pf) + p := packfile.NewPackfile(index, fixtures.Filesystem, f.Packfile()) defer p.Close() for _, h := range expectedHashes { @@ -145,11 +137,8 @@ func (s *PackfileSuite) TestDecodeByTypeRefDelta(c *C) { f := fixtures.Basic().ByTag("ref-delta").One() index := getIndexFromIdxFile(f.Idx()) - fs := osfs.New("") - pf, err := fs.Open(f.Packfile().Name()) - c.Assert(err, IsNil) - packfile := packfile.NewPackfile(index, fs, pf) + packfile := packfile.NewPackfile(index, fixtures.Filesystem, f.Packfile()) defer packfile.Close() iter, err := packfile.GetByType(plumbing.CommitObject) @@ -161,6 +150,7 @@ func (s *PackfileSuite) TestDecodeByTypeRefDelta(c *C) { if err == io.EOF { break } + count++ c.Assert(err, IsNil) c.Assert(obj.Type(), Equals, plumbing.CommitObject) @@ -180,11 +170,8 @@ func (s *PackfileSuite) TestDecodeByType(c *C) { fixtures.Basic().ByTag("packfile").Test(c, func(f *fixtures.Fixture) { for _, t := range ts { index := getIndexFromIdxFile(f.Idx()) - fs := osfs.New("") - pf, err := fs.Open(f.Packfile().Name()) - c.Assert(err, IsNil) - packfile := packfile.NewPackfile(index, fs, pf) + packfile := packfile.NewPackfile(index, fixtures.Filesystem, f.Packfile()) defer packfile.Close() iter, err := packfile.GetByType(t) @@ -201,14 +188,11 @@ func (s *PackfileSuite) TestDecodeByType(c *C) { func (s *PackfileSuite) TestDecodeByTypeConstructor(c *C) { f := fixtures.Basic().ByTag("packfile").One() index := getIndexFromIdxFile(f.Idx()) - fs := osfs.New("") - pf, err := fs.Open(f.Packfile().Name()) - c.Assert(err, IsNil) - packfile := packfile.NewPackfile(index, fs, pf) + packfile := packfile.NewPackfile(index, fixtures.Filesystem, f.Packfile()) defer packfile.Close() - _, err = packfile.GetByType(plumbing.OFSDeltaObject) + _, err := packfile.GetByType(plumbing.OFSDeltaObject) c.Assert(err, Equals, plumbing.ErrInvalidType) _, err = packfile.GetByType(plumbing.REFDeltaObject) @@ -269,24 +253,20 @@ func assertObjects(c *C, s storer.EncodedObjectStorer, expects []string) { } func getIndexFromIdxFile(r io.Reader) idxfile.Index { - idxf := idxfile.NewMemoryIndex() - d := idxfile.NewDecoder(r) - if err := d.Decode(idxf); err != nil { + idx := idxfile.NewMemoryIndex() + if err := idxfile.NewDecoder(r).Decode(idx); err != nil { panic(err) } - return idxf + return idx } func (s *PackfileSuite) TestSize(c *C) { f := fixtures.Basic().ByTag("ref-delta").One() index := getIndexFromIdxFile(f.Idx()) - fs := osfs.New("") - pf, err := fs.Open(f.Packfile().Name()) - c.Assert(err, IsNil) - packfile := packfile.NewPackfile(index, fs, pf) + packfile := packfile.NewPackfile(index, fixtures.Filesystem, f.Packfile()) defer packfile.Close() // Get the size of binary.jpg, which is not delta-encoded. diff --git a/plumbing/format/packfile/parser_test.go b/plumbing/format/packfile/parser_test.go index 57a9c17..b0b4af8 100644 --- a/plumbing/format/packfile/parser_test.go +++ b/plumbing/format/packfile/parser_test.go @@ -2,14 +2,16 @@ package packfile_test import ( "io" + "os" "testing" - git "github.com/go-git/go-git/v5" + "github.com/go-git/go-billy/v5/osfs" + "github.com/go-git/go-billy/v5/util" + fixtures "github.com/go-git/go-git-fixtures/v4" + "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing/format/packfile" "github.com/go-git/go-git/v5/plumbing/storer" - - fixtures "github.com/go-git/go-git-fixtures/v4" . "gopkg.in/check.v1" ) @@ -78,40 +80,46 @@ func (s *ParserSuite) TestParserHashes(c *C) { } func (s *ParserSuite) TestThinPack(c *C) { + fs := osfs.New(os.TempDir()) + path, err := util.TempDir(fs, "", "") + c.Assert(err, IsNil) // Initialize an empty repository - fs, err := git.PlainInit(c.MkDir(), true) + r, err := git.PlainInit(path, true) c.Assert(err, IsNil) // Try to parse a thin pack without having the required objects in the repo to // see if the correct errors are returned thinpack := fixtures.ByTag("thinpack").One() scanner := packfile.NewScanner(thinpack.Packfile()) - parser, err := packfile.NewParserWithStorage(scanner, fs.Storer) // ParserWithStorage writes to the storer all parsed objects! + parser, err := packfile.NewParserWithStorage(scanner, r.Storer) // ParserWithStorage writes to the storer all parsed objects! c.Assert(err, IsNil) _, err = parser.Parse() c.Assert(err, Equals, plumbing.ErrObjectNotFound) + path, err = util.TempDir(fs, "", "") + c.Assert(err, IsNil) + // start over with a clean repo - fs, err = git.PlainInit(c.MkDir(), true) + r, err = git.PlainInit(path, true) c.Assert(err, IsNil) // Now unpack a base packfile into our empty repo: f := fixtures.ByURL("https://github.com/spinnaker/spinnaker.git").One() - w, err := fs.Storer.(storer.PackfileWriter).PackfileWriter() + w, err := r.Storer.(storer.PackfileWriter).PackfileWriter() c.Assert(err, IsNil) _, err = io.Copy(w, f.Packfile()) c.Assert(err, IsNil) w.Close() // Check that the test object that will come with our thin pack is *not* in the repo - _, err = fs.Storer.EncodedObject(plumbing.CommitObject, plumbing.NewHash(thinpack.Head)) + _, err = r.Storer.EncodedObject(plumbing.CommitObject, plumbing.NewHash(thinpack.Head)) c.Assert(err, Equals, plumbing.ErrObjectNotFound) // Now unpack the thin pack: scanner = packfile.NewScanner(thinpack.Packfile()) - parser, err = packfile.NewParserWithStorage(scanner, fs.Storer) // ParserWithStorage writes to the storer all parsed objects! + parser, err = packfile.NewParserWithStorage(scanner, r.Storer) // ParserWithStorage writes to the storer all parsed objects! c.Assert(err, IsNil) h, err := parser.Parse() @@ -119,7 +127,7 @@ func (s *ParserSuite) TestThinPack(c *C) { c.Assert(h, Equals, plumbing.NewHash("1288734cbe0b95892e663221d94b95de1f5d7be8")) // Check that our test object is now accessible - _, err = fs.Storer.EncodedObject(plumbing.CommitObject, plumbing.NewHash(thinpack.Head)) + _, err = r.Storer.EncodedObject(plumbing.CommitObject, plumbing.NewHash(thinpack.Head)) c.Assert(err, IsNil) } |