| 1 |
package server_test |
| 2 |
|
| 3 |
import ( |
| 4 |
"context" |
| 5 |
|
| 6 |
"github.com/go-git/go-git/v5/plumbing" |
| 7 |
"github.com/go-git/go-git/v5/plumbing/protocol/packp" |
| 8 |
"github.com/go-git/go-git/v5/plumbing/transport" |
| 9 |
|
| 10 |
fixtures "github.com/go-git/go-git-fixtures/v4" |
| 11 |
. "gopkg.in/check.v1" |
| 12 |
) |
| 13 |
|
| 14 |
type ReceivePackSuite struct { |
| 15 |
BaseSuite |
| 16 |
} |
| 17 |
|
| 18 |
var _ = Suite(&ReceivePackSuite{}) |
| 19 |
|
| 20 |
func (s *ReceivePackSuite) SetUpSuite(c *C) { |
| 21 |
s.BaseSuite.SetUpSuite(c) |
| 22 |
s.ReceivePackSuite.Client = s.client |
| 23 |
} |
| 24 |
|
| 25 |
func (s *ReceivePackSuite) SetUpTest(c *C) { |
| 26 |
s.prepareRepositories(c) |
| 27 |
} |
| 28 |
|
| 29 |
func (s *ReceivePackSuite) TearDownTest(c *C) { |
| 30 |
s.Suite.TearDownSuite(c) |
| 31 |
} |
| 32 |
|
| 33 |
// Overwritten, server returns error earlier. |
| 34 |
func (s *ReceivePackSuite) TestAdvertisedReferencesNotExists(c *C) { |
| 35 |
r, err := s.Client.NewReceivePackSession(s.NonExistentEndpoint, s.EmptyAuth) |
| 36 |
c.Assert(err, Equals, transport.ErrRepositoryNotFound) |
| 37 |
c.Assert(r, IsNil) |
| 38 |
} |
| 39 |
|
| 40 |
func (s *ReceivePackSuite) TestReceivePackWithNilPackfile(c *C) { |
| 41 |
endpoint := s.Endpoint |
| 42 |
auth := s.EmptyAuth |
| 43 |
|
| 44 |
fixture := fixtures.Basic().ByTag("packfile").One() |
| 45 |
req := packp.NewReferenceUpdateRequest() |
| 46 |
req.Commands = []*packp.Command{ |
| 47 |
{Name: "refs/heads/newbranch", Old: plumbing.NewHash(fixture.Head), New: plumbing.ZeroHash}, |
| 48 |
} |
| 49 |
// default is already nil, but be explicit since this is what the test is for |
| 50 |
req.Packfile = nil |
| 51 |
|
| 52 |
comment := Commentf( |
| 53 |
"failed with ep=%s fixture=%s", |
| 54 |
endpoint.String(), fixture.URL, |
| 55 |
) |
| 56 |
|
| 57 |
r, err := s.Client.NewReceivePackSession(endpoint, auth) |
| 58 |
c.Assert(err, IsNil, comment) |
| 59 |
defer func() { c.Assert(r.Close(), IsNil, comment) }() |
| 60 |
|
| 61 |
report, err := r.ReceivePack(context.Background(), req) |
| 62 |
c.Assert(report, IsNil, comment) |
| 63 |
c.Assert(err, NotNil, comment) |
| 64 |
} |