| 1 |
package packp |
| 2 |
|
| 3 |
import ( |
| 4 |
"bytes" |
| 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 UploadPackRequestSuite struct{} |
| 13 |
|
| 14 |
var _ = Suite(&UploadPackRequestSuite{}) |
| 15 |
|
| 16 |
func (s *UploadPackRequestSuite) TestNewUploadPackRequestFromCapabilities(c *C) { |
| 17 |
cap := capability.NewList() |
| 18 |
cap.Set(capability.Agent, "foo") |
| 19 |
|
| 20 |
r := NewUploadPackRequestFromCapabilities(cap) |
| 21 |
c.Assert(r.Capabilities.String(), Equals, "agent=go-git/5.x") |
| 22 |
} |
| 23 |
|
| 24 |
func (s *UploadPackRequestSuite) TestIsEmpty(c *C) { |
| 25 |
r := NewUploadPackRequest() |
| 26 |
r.Wants = append(r.Wants, plumbing.NewHash("d82f291cde9987322c8a0c81a325e1ba6159684c")) |
| 27 |
r.Wants = append(r.Wants, plumbing.NewHash("2b41ef280fdb67a9b250678686a0c3e03b0a9989")) |
| 28 |
r.Haves = append(r.Haves, plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5")) |
| 29 |
|
| 30 |
c.Assert(r.IsEmpty(), Equals, false) |
| 31 |
|
| 32 |
r = NewUploadPackRequest() |
| 33 |
r.Wants = append(r.Wants, plumbing.NewHash("d82f291cde9987322c8a0c81a325e1ba6159684c")) |
| 34 |
r.Wants = append(r.Wants, plumbing.NewHash("2b41ef280fdb67a9b250678686a0c3e03b0a9989")) |
| 35 |
r.Haves = append(r.Haves, plumbing.NewHash("d82f291cde9987322c8a0c81a325e1ba6159684c")) |
| 36 |
|
| 37 |
c.Assert(r.IsEmpty(), Equals, false) |
| 38 |
|
| 39 |
r = NewUploadPackRequest() |
| 40 |
r.Wants = append(r.Wants, plumbing.NewHash("d82f291cde9987322c8a0c81a325e1ba6159684c")) |
| 41 |
r.Haves = append(r.Haves, plumbing.NewHash("d82f291cde9987322c8a0c81a325e1ba6159684c")) |
| 42 |
|
| 43 |
c.Assert(r.IsEmpty(), Equals, true) |
| 44 |
|
| 45 |
r = NewUploadPackRequest() |
| 46 |
r.Wants = append(r.Wants, plumbing.NewHash("d82f291cde9987322c8a0c81a325e1ba6159684c")) |
| 47 |
r.Haves = append(r.Haves, plumbing.NewHash("d82f291cde9987322c8a0c81a325e1ba6159684c")) |
| 48 |
r.Shallows = append(r.Shallows, plumbing.NewHash("2b41ef280fdb67a9b250678686a0c3e03b0a9989")) |
| 49 |
|
| 50 |
c.Assert(r.IsEmpty(), Equals, false) |
| 51 |
} |
| 52 |
|
| 53 |
type UploadHavesSuite struct{} |
| 54 |
|
| 55 |
var _ = Suite(&UploadHavesSuite{}) |
| 56 |
|
| 57 |
func (s *UploadHavesSuite) TestEncode(c *C) { |
| 58 |
uh := &UploadHaves{} |
| 59 |
uh.Haves = append(uh.Haves, |
| 60 |
plumbing.NewHash("1111111111111111111111111111111111111111"), |
| 61 |
plumbing.NewHash("3333333333333333333333333333333333333333"), |
| 62 |
plumbing.NewHash("1111111111111111111111111111111111111111"), |
| 63 |
plumbing.NewHash("2222222222222222222222222222222222222222"), |
| 64 |
plumbing.NewHash("1111111111111111111111111111111111111111"), |
| 65 |
) |
| 66 |
|
| 67 |
buf := bytes.NewBuffer(nil) |
| 68 |
err := uh.Encode(buf, true) |
| 69 |
c.Assert(err, IsNil) |
| 70 |
c.Assert(buf.String(), Equals, ""+ |
| 71 |
"0032have 1111111111111111111111111111111111111111\n"+ |
| 72 |
"0032have 2222222222222222222222222222222222222222\n"+ |
| 73 |
"0032have 3333333333333333333333333333333333333333\n"+ |
| 74 |
"0000", |
| 75 |
) |
| 76 |
} |