diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-12-01 09:59:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-01 09:59:19 +0100 |
commit | c15bf1dff332873644290db0e186b8f5ad9b8fb2 (patch) | |
tree | 1dd79212333823b70f2792ad116864ea127e4a1c /plumbing/protocol/packp/ulreq_test.go | |
parent | 7de79aef5d4aa3100382d4df3e99525f9949e8d1 (diff) | |
download | go-git-c15bf1dff332873644290db0e186b8f5ad9b8fb2.tar.gz |
capabilities: full integration (#151)
* format/pktline: fix readPayloadLen err handling
* protocol/pakp: UploadReq validation and creation of capabilities
* protocol/pakp: AdvRef tests
* protocol/pakp: capability.List.Delete
* protocol: filter unsupported capabilities
* remote capability negociation
* transport: UploadRequest validation
* requested changes
Diffstat (limited to 'plumbing/protocol/packp/ulreq_test.go')
-rw-r--r-- | plumbing/protocol/packp/ulreq_test.go | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/plumbing/protocol/packp/ulreq_test.go b/plumbing/protocol/packp/ulreq_test.go index 5e9e978..53626ee 100644 --- a/plumbing/protocol/packp/ulreq_test.go +++ b/plumbing/protocol/packp/ulreq_test.go @@ -9,8 +9,109 @@ import ( "gopkg.in/src-d/go-git.v4/plumbing" "gopkg.in/src-d/go-git.v4/plumbing/format/pktline" "gopkg.in/src-d/go-git.v4/plumbing/protocol/packp/capability" + + . "gopkg.in/check.v1" ) +type UlReqSuite struct{} + +var _ = Suite(&UlReqSuite{}) + +func (s *UlReqSuite) TestNewUploadRequestFromCapabilities(c *C) { + cap := capability.NewList() + cap.Set(capability.Sideband) + cap.Set(capability.Sideband64k) + cap.Set(capability.MultiACK) + cap.Set(capability.MultiACKDetailed) + cap.Set(capability.ThinPack) + cap.Set(capability.OFSDelta) + cap.Set(capability.Agent, "foo") + + r := NewUploadRequestFromCapabilities(cap) + c.Assert(r.Capabilities.String(), Equals, + "multi_ack_detailed thin-pack ofs-delta agent=go-git/4.x", + ) +} + +func (s *UlReqSuite) TestValidateWants(c *C) { + r := NewUploadRequest() + err := r.Validate() + c.Assert(err, NotNil) + + r.Wants = append(r.Wants, plumbing.NewHash("1111111111111111111111111111111111111111")) + err = r.Validate() + c.Assert(err, IsNil) +} + +func (s *UlReqSuite) TestValidateShallows(c *C) { + r := NewUploadRequest() + r.Wants = append(r.Wants, plumbing.NewHash("1111111111111111111111111111111111111111")) + r.Shallows = append(r.Shallows, plumbing.NewHash("2222222222222222222222222222222222222222")) + err := r.Validate() + c.Assert(err, NotNil) + + r.Capabilities.Set(capability.Shallow) + err = r.Validate() + c.Assert(err, IsNil) +} + +func (s *UlReqSuite) TestValidateDepthCommits(c *C) { + r := NewUploadRequest() + r.Wants = append(r.Wants, plumbing.NewHash("1111111111111111111111111111111111111111")) + r.Depth = DepthCommits(42) + + err := r.Validate() + c.Assert(err, NotNil) + + r.Capabilities.Set(capability.Shallow) + err = r.Validate() + c.Assert(err, IsNil) +} + +func (s *UlReqSuite) TestValidateDepthReference(c *C) { + r := NewUploadRequest() + r.Wants = append(r.Wants, plumbing.NewHash("1111111111111111111111111111111111111111")) + r.Depth = DepthReference("1111111111111111111111111111111111111111") + + err := r.Validate() + c.Assert(err, NotNil) + + r.Capabilities.Set(capability.DeepenNot) + err = r.Validate() + c.Assert(err, IsNil) +} + +func (s *UlReqSuite) TestValidateDepthSince(c *C) { + r := NewUploadRequest() + r.Wants = append(r.Wants, plumbing.NewHash("1111111111111111111111111111111111111111")) + r.Depth = DepthSince(time.Now()) + + err := r.Validate() + c.Assert(err, NotNil) + + r.Capabilities.Set(capability.DeepenSince) + err = r.Validate() + c.Assert(err, IsNil) +} + +func (s *UlReqSuite) TestValidateConflictSideband(c *C) { + r := NewUploadRequest() + r.Wants = append(r.Wants, plumbing.NewHash("1111111111111111111111111111111111111111")) + r.Capabilities.Set(capability.Sideband) + r.Capabilities.Set(capability.Sideband64k) + err := r.Validate() + c.Assert(err, NotNil) +} + +func (s *UlReqSuite) TestValidateConflictMultiACK(c *C) { + r := NewUploadRequest() + r.Wants = append(r.Wants, plumbing.NewHash("1111111111111111111111111111111111111111")) + r.Capabilities.Set(capability.MultiACK) + r.Capabilities.Set(capability.MultiACKDetailed) + err := r.Validate() + c.Assert(err, NotNil) +} + func ExampleUlReqEncoder_Encode() { // Create an empty UlReq with the contents you want... ur := NewUploadRequest() |