| 1 |
package packp |
| 2 |
|
| 3 |
import ( |
| 4 |
"time" |
| 5 |
|
| 6 |
"github.com/go-git/go-git/v5/plumbing" |
| 7 |
"github.com/go-git/go-git/v5/plumbing/protocol/packp/capability" |
| 8 |
|
| 9 |
. "gopkg.in/check.v1" |
| 10 |
) |
| 11 |
|
| 12 |
type UlReqSuite struct{} |
| 13 |
|
| 14 |
var _ = Suite(&UlReqSuite{}) |
| 15 |
|
| 16 |
func (s *UlReqSuite) TestNewUploadRequestFromCapabilities(c *C) { |
| 17 |
cap := capability.NewList() |
| 18 |
cap.Set(capability.Sideband) |
| 19 |
cap.Set(capability.Sideband64k) |
| 20 |
cap.Set(capability.MultiACK) |
| 21 |
cap.Set(capability.MultiACKDetailed) |
| 22 |
cap.Set(capability.ThinPack) |
| 23 |
cap.Set(capability.OFSDelta) |
| 24 |
cap.Set(capability.Agent, "foo") |
| 25 |
|
| 26 |
r := NewUploadRequestFromCapabilities(cap) |
| 27 |
c.Assert(r.Capabilities.String(), Equals, |
| 28 |
"multi_ack_detailed side-band-64k thin-pack ofs-delta agent=go-git/5.x", |
| 29 |
) |
| 30 |
} |
| 31 |
|
| 32 |
func (s *UlReqSuite) TestValidateWants(c *C) { |
| 33 |
r := NewUploadRequest() |
| 34 |
err := r.Validate() |
| 35 |
c.Assert(err, NotNil) |
| 36 |
|
| 37 |
r.Wants = append(r.Wants, plumbing.NewHash("1111111111111111111111111111111111111111")) |
| 38 |
err = r.Validate() |
| 39 |
c.Assert(err, IsNil) |
| 40 |
} |
| 41 |
|
| 42 |
func (s *UlReqSuite) TestValidateShallows(c *C) { |
| 43 |
r := NewUploadRequest() |
| 44 |
r.Wants = append(r.Wants, plumbing.NewHash("1111111111111111111111111111111111111111")) |
| 45 |
r.Shallows = append(r.Shallows, plumbing.NewHash("2222222222222222222222222222222222222222")) |
| 46 |
err := r.Validate() |
| 47 |
c.Assert(err, NotNil) |
| 48 |
|
| 49 |
r.Capabilities.Set(capability.Shallow) |
| 50 |
err = r.Validate() |
| 51 |
c.Assert(err, IsNil) |
| 52 |
} |
| 53 |
|
| 54 |
func (s *UlReqSuite) TestValidateDepthCommits(c *C) { |
| 55 |
r := NewUploadRequest() |
| 56 |
r.Wants = append(r.Wants, plumbing.NewHash("1111111111111111111111111111111111111111")) |
| 57 |
r.Depth = DepthCommits(42) |
| 58 |
|
| 59 |
err := r.Validate() |
| 60 |
c.Assert(err, NotNil) |
| 61 |
|
| 62 |
r.Capabilities.Set(capability.Shallow) |
| 63 |
err = r.Validate() |
| 64 |
c.Assert(err, IsNil) |
| 65 |
} |
| 66 |
|
| 67 |
func (s *UlReqSuite) TestValidateDepthReference(c *C) { |
| 68 |
r := NewUploadRequest() |
| 69 |
r.Wants = append(r.Wants, plumbing.NewHash("1111111111111111111111111111111111111111")) |
| 70 |
r.Depth = DepthReference("1111111111111111111111111111111111111111") |
| 71 |
|
| 72 |
err := r.Validate() |
| 73 |
c.Assert(err, NotNil) |
| 74 |
|
| 75 |
r.Capabilities.Set(capability.DeepenNot) |
| 76 |
err = r.Validate() |
| 77 |
c.Assert(err, IsNil) |
| 78 |
} |
| 79 |
|
| 80 |
func (s *UlReqSuite) TestValidateDepthSince(c *C) { |
| 81 |
r := NewUploadRequest() |
| 82 |
r.Wants = append(r.Wants, plumbing.NewHash("1111111111111111111111111111111111111111")) |
| 83 |
r.Depth = DepthSince(time.Now()) |
| 84 |
|
| 85 |
err := r.Validate() |
| 86 |
c.Assert(err, NotNil) |
| 87 |
|
| 88 |
r.Capabilities.Set(capability.DeepenSince) |
| 89 |
err = r.Validate() |
| 90 |
c.Assert(err, IsNil) |
| 91 |
} |
| 92 |
|
| 93 |
func (s *UlReqSuite) TestValidateConflictSideband(c *C) { |
| 94 |
r := NewUploadRequest() |
| 95 |
r.Wants = append(r.Wants, plumbing.NewHash("1111111111111111111111111111111111111111")) |
| 96 |
r.Capabilities.Set(capability.Sideband) |
| 97 |
r.Capabilities.Set(capability.Sideband64k) |
| 98 |
err := r.Validate() |
| 99 |
c.Assert(err, NotNil) |
| 100 |
} |
| 101 |
|
| 102 |
func (s *UlReqSuite) TestValidateConflictMultiACK(c *C) { |
| 103 |
r := NewUploadRequest() |
| 104 |
r.Wants = append(r.Wants, plumbing.NewHash("1111111111111111111111111111111111111111")) |
| 105 |
r.Capabilities.Set(capability.MultiACK) |
| 106 |
r.Capabilities.Set(capability.MultiACKDetailed) |
| 107 |
err := r.Validate() |
| 108 |
c.Assert(err, NotNil) |
| 109 |
} |