diff options
author | Santiago M. Mola <santi@mola.io> | 2017-01-04 11:18:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-04 11:18:41 +0100 |
commit | 841abfb7dc640755c443432064252907e3e55c95 (patch) | |
tree | 8af69dcd3b301a10a3e493e2cd805cdec6dcaecd /plumbing/transport/http/upload_pack_test.go | |
parent | 90d67bb648ae32d5b1a0f7b1af011da6dfb24315 (diff) | |
download | go-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/http/upload_pack_test.go')
-rw-r--r-- | plumbing/transport/http/upload_pack_test.go | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/plumbing/transport/http/upload_pack_test.go b/plumbing/transport/http/upload_pack_test.go new file mode 100644 index 0000000..d3e4989 --- /dev/null +++ b/plumbing/transport/http/upload_pack_test.go @@ -0,0 +1,60 @@ +package http + +import ( + "io/ioutil" + + "gopkg.in/src-d/go-git.v4/plumbing" + "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/plumbing/transport/test" + + . "gopkg.in/check.v1" +) + +type UploadPackSuite struct { + test.UploadPackSuite +} + +var _ = Suite(&UploadPackSuite{}) + +func (s *UploadPackSuite) SetUpSuite(c *C) { + s.UploadPackSuite.Client = DefaultClient + + ep, err := transport.NewEndpoint("https://github.com/git-fixtures/basic.git") + c.Assert(err, IsNil) + s.UploadPackSuite.Endpoint = ep + + ep, err = transport.NewEndpoint("https://github.com/git-fixtures/empty.git") + c.Assert(err, IsNil) + s.UploadPackSuite.EmptyEndpoint = ep + + ep, err = transport.NewEndpoint("https://github.com/git-fixtures/non-existent.git") + c.Assert(err, IsNil) + s.UploadPackSuite.NonExistentEndpoint = ep +} + +// Overwritten, different behaviour for HTTP. +func (s *UploadPackSuite) TestAdvertisedReferencesNotExists(c *C) { + r, err := s.Client.NewUploadPackSession(s.NonExistentEndpoint) + c.Assert(err, IsNil) + info, err := r.AdvertisedReferences() + c.Assert(err, Equals, transport.ErrAuthorizationRequired) + c.Assert(info, IsNil) +} + +func (s *UploadPackSuite) TestuploadPackRequestToReader(c *C) { + r := packp.NewUploadPackRequest() + r.Wants = append(r.Wants, plumbing.NewHash("d82f291cde9987322c8a0c81a325e1ba6159684c")) + r.Wants = append(r.Wants, plumbing.NewHash("2b41ef280fdb67a9b250678686a0c3e03b0a9989")) + r.Haves = append(r.Haves, plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5")) + + sr, err := uploadPackRequestToReader(r) + c.Assert(err, IsNil) + b, _ := ioutil.ReadAll(sr) + c.Assert(string(b), Equals, + "0032want 2b41ef280fdb67a9b250678686a0c3e03b0a9989\n"+ + "0032want d82f291cde9987322c8a0c81a325e1ba6159684c\n0000"+ + "0032have 6ecf0ef2c2dffb796033e5a02219af86ec6584e5\n0000"+ + "0009done\n", + ) +} |