aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/transport/test/upload_pack.go
diff options
context:
space:
mode:
authorSantiago M. Mola <santi@mola.io>2017-01-04 11:18:41 +0100
committerGitHub <noreply@github.com>2017-01-04 11:18:41 +0100
commit841abfb7dc640755c443432064252907e3e55c95 (patch)
tree8af69dcd3b301a10a3e493e2cd805cdec6dcaecd /plumbing/transport/test/upload_pack.go
parent90d67bb648ae32d5b1a0f7b1af011da6dfb24315 (diff)
downloadgo-git-841abfb7dc640755c443432064252907e3e55c95.tar.gz
server: add git server implementation (#190)
* server: add generic server implementation (transport-independent), both for git-upload-pack and git-receive-pack. * server: move internal functions to internal/common. * cli: add git-receive-pack and git-upload-pack implementations. * format/packfile: add UpdateObjectStorage function, extracted from Remote. * transport: implement tranport RPC-like, only with git-upload-pack and git-receive-pack methods. Client renamed to Transport. * storer: add storer.Storer interface. * protocol/packp: add UploadPackResponse constructor with packfile. * protocol/packp: fix UploadPackResponse encoding, add tests. * protocol/packp/capability: implement All.
Diffstat (limited to 'plumbing/transport/test/upload_pack.go')
-rw-r--r--plumbing/transport/test/upload_pack.go196
1 files changed, 196 insertions, 0 deletions
diff --git a/plumbing/transport/test/upload_pack.go b/plumbing/transport/test/upload_pack.go
new file mode 100644
index 0000000..5af4b29
--- /dev/null
+++ b/plumbing/transport/test/upload_pack.go
@@ -0,0 +1,196 @@
+// Package test implements common test suite for different transport
+// implementations.
+//
+package test
+
+import (
+ "bytes"
+ "io"
+ "io/ioutil"
+
+ "gopkg.in/src-d/go-git.v4/plumbing"
+ "gopkg.in/src-d/go-git.v4/plumbing/format/packfile"
+ "gopkg.in/src-d/go-git.v4/plumbing/protocol/packp"
+ "gopkg.in/src-d/go-git.v4/plumbing/transport"
+ "gopkg.in/src-d/go-git.v4/storage/memory"
+
+ . "gopkg.in/check.v1"
+ "gopkg.in/src-d/go-git.v4/plumbing/protocol/packp/capability"
+)
+
+type UploadPackSuite struct {
+ Endpoint transport.Endpoint
+ EmptyEndpoint transport.Endpoint
+ NonExistentEndpoint transport.Endpoint
+ Client transport.Transport
+}
+
+func (s *UploadPackSuite) TestAdvertisedReferencesEmpty(c *C) {
+ r, err := s.Client.NewUploadPackSession(s.EmptyEndpoint)
+ c.Assert(err, IsNil)
+ ar, err := r.AdvertisedReferences()
+ c.Assert(err, Equals, transport.ErrEmptyRemoteRepository)
+ c.Assert(ar, IsNil)
+}
+
+func (s *UploadPackSuite) TestAdvertisedReferencesNotExists(c *C) {
+ r, err := s.Client.NewUploadPackSession(s.NonExistentEndpoint)
+ c.Assert(err, IsNil)
+ ar, err := r.AdvertisedReferences()
+ c.Assert(err, Equals, transport.ErrRepositoryNotFound)
+ c.Assert(ar, IsNil)
+
+ r, err = s.Client.NewUploadPackSession(s.NonExistentEndpoint)
+ c.Assert(err, IsNil)
+ req := packp.NewUploadPackRequest()
+ req.Wants = append(req.Wants, plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"))
+ reader, err := r.UploadPack(req)
+ c.Assert(err, Equals, transport.ErrRepositoryNotFound)
+ c.Assert(reader, IsNil)
+}
+
+func (s *UploadPackSuite) TestCallAdvertisedReferenceTwice(c *C) {
+ r, err := s.Client.NewUploadPackSession(s.Endpoint)
+ c.Assert(err, IsNil)
+ ar1, err := r.AdvertisedReferences()
+ c.Assert(err, IsNil)
+ c.Assert(ar1, NotNil)
+ ar2, err := r.AdvertisedReferences()
+ c.Assert(err, IsNil)
+ c.Assert(ar2, DeepEquals, ar1)
+}
+
+func (s *UploadPackSuite) TestDefaultBranch(c *C) {
+ r, err := s.Client.NewUploadPackSession(s.Endpoint)
+ c.Assert(err, IsNil)
+ defer func() { c.Assert(r.Close(), IsNil) }()
+
+ info, err := r.AdvertisedReferences()
+ c.Assert(err, IsNil)
+ symrefs := info.Capabilities.Get(capability.SymRef)
+ c.Assert(symrefs, HasLen, 1)
+ c.Assert(symrefs[0], Equals, "HEAD:refs/heads/master")
+}
+
+func (s *UploadPackSuite) TestAdvertisedReferencesFilterUnsupported(c *C) {
+ r, err := s.Client.NewUploadPackSession(s.Endpoint)
+ c.Assert(err, IsNil)
+ defer func() { c.Assert(r.Close(), IsNil) }()
+
+ info, err := r.AdvertisedReferences()
+ c.Assert(err, IsNil)
+ c.Assert(info.Capabilities.Supports(capability.MultiACK), Equals, false)
+}
+
+func (s *UploadPackSuite) TestCapabilities(c *C) {
+ r, err := s.Client.NewUploadPackSession(s.Endpoint)
+ c.Assert(err, IsNil)
+ defer func() { c.Assert(r.Close(), IsNil) }()
+
+ info, err := r.AdvertisedReferences()
+ c.Assert(err, IsNil)
+ c.Assert(info.Capabilities.Get(capability.Agent), HasLen, 1)
+}
+
+func (s *UploadPackSuite) TestFullUploadPack(c *C) {
+ r, err := s.Client.NewUploadPackSession(s.Endpoint)
+ c.Assert(err, IsNil)
+ defer func() { c.Assert(r.Close(), IsNil) }()
+
+ info, err := r.AdvertisedReferences()
+ c.Assert(err, IsNil)
+ c.Assert(info, NotNil)
+
+ req := packp.NewUploadPackRequest()
+ req.Wants = append(req.Wants, plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"))
+
+ reader, err := r.UploadPack(req)
+ c.Assert(err, IsNil)
+
+ s.checkObjectNumber(c, reader, 28)
+}
+
+func (s *UploadPackSuite) TestUploadPack(c *C) {
+ r, err := s.Client.NewUploadPackSession(s.Endpoint)
+ c.Assert(err, IsNil)
+ defer func() { c.Assert(r.Close(), IsNil) }()
+
+ req := packp.NewUploadPackRequest()
+ req.Wants = append(req.Wants, plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"))
+
+ reader, err := r.UploadPack(req)
+ c.Assert(err, IsNil)
+
+ s.checkObjectNumber(c, reader, 28)
+}
+
+func (s *UploadPackSuite) TestUploadPackInvalidReq(c *C) {
+ r, err := s.Client.NewUploadPackSession(s.Endpoint)
+ c.Assert(err, IsNil)
+ defer func() { c.Assert(r.Close(), IsNil) }()
+
+ req := packp.NewUploadPackRequest()
+ req.Wants = append(req.Wants, plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"))
+ req.Capabilities.Set(capability.Sideband)
+ req.Capabilities.Set(capability.Sideband64k)
+
+ _, err = r.UploadPack(req)
+ c.Assert(err, NotNil)
+}
+
+func (s *UploadPackSuite) TestUploadPackNoChanges(c *C) {
+ r, err := s.Client.NewUploadPackSession(s.Endpoint)
+ c.Assert(err, IsNil)
+ defer func() { c.Assert(r.Close(), IsNil) }()
+
+ req := packp.NewUploadPackRequest()
+ req.Wants = append(req.Wants, plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"))
+ req.Haves = append(req.Haves, plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"))
+
+ reader, err := r.UploadPack(req)
+ c.Assert(err, Equals, transport.ErrEmptyUploadPackRequest)
+ c.Assert(reader, IsNil)
+}
+
+func (s *UploadPackSuite) TestUploadPackMulti(c *C) {
+ r, err := s.Client.NewUploadPackSession(s.Endpoint)
+ c.Assert(err, IsNil)
+ defer func() { c.Assert(r.Close(), IsNil) }()
+
+ req := packp.NewUploadPackRequest()
+ req.Wants = append(req.Wants, plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"))
+ req.Wants = append(req.Wants, plumbing.NewHash("e8d3ffab552895c19b9fcf7aa264d277cde33881"))
+
+ reader, err := r.UploadPack(req)
+ c.Assert(err, IsNil)
+
+ s.checkObjectNumber(c, reader, 31)
+}
+
+func (s *UploadPackSuite) TestFetchError(c *C) {
+ r, err := s.Client.NewUploadPackSession(s.Endpoint)
+ c.Assert(err, IsNil)
+
+ req := packp.NewUploadPackRequest()
+ req.Wants = append(req.Wants, plumbing.NewHash("1111111111111111111111111111111111111111"))
+
+ reader, err := r.UploadPack(req)
+ c.Assert(err, NotNil)
+ c.Assert(reader, IsNil)
+
+ //XXX: We do not test Close error, since implementations might return
+ // different errors if a previous error was found.
+}
+
+func (s *UploadPackSuite) checkObjectNumber(c *C, r io.Reader, n int) {
+ b, err := ioutil.ReadAll(r)
+ c.Assert(err, IsNil)
+ buf := bytes.NewBuffer(b)
+ scanner := packfile.NewScanner(buf)
+ storage := memory.NewStorage()
+ d, err := packfile.NewDecoder(scanner, storage)
+ c.Assert(err, IsNil)
+ _, err = d.Decode()
+ c.Assert(err, IsNil)
+ c.Assert(len(storage.Objects), Equals, n)
+}