Debian Codegraph @

plumbing/transport/file/upload_pack_test.go

raw
1 package file
2
3 import (
4 "os"
5
6 "github.com/go-git/go-git/v5/plumbing/transport"
7 "github.com/go-git/go-git/v5/plumbing/transport/test"
8
9 fixtures "github.com/go-git/go-git-fixtures/v4"
10 . "gopkg.in/check.v1"
11 )
12
13 type UploadPackSuite struct {
14 CommonSuite
15 test.UploadPackSuite
16 }
17
18 var _ = Suite(&UploadPackSuite{})
19
20 func (s *UploadPackSuite) SetUpSuite(c *C) {
21 s.CommonSuite.SetUpSuite(c)
22
23 s.UploadPackSuite.Client = DefaultClient
24
25 fixture := fixtures.Basic().One()
26 path := fixture.DotGit().Root()
27 ep, err := transport.NewEndpoint(path)
28 c.Assert(err, IsNil)
29 s.Endpoint = ep
30
31 fixture = fixtures.ByTag("empty").One()
32 path = fixture.DotGit().Root()
33 ep, err = transport.NewEndpoint(path)
34 c.Assert(err, IsNil)
35 s.EmptyEndpoint = ep
36
37 ep, err = transport.NewEndpoint("non-existent")
38 c.Assert(err, IsNil)
39 s.NonExistentEndpoint = ep
40 }
41
42 // TODO: fix test
43 func (s *UploadPackSuite) TestCommandNoOutput(c *C) {
44 c.Skip("failing test")
45
46 if _, err := os.Stat("/bin/true"); os.IsNotExist(err) {
47 c.Skip("/bin/true not found")
48 }
49
50 client := NewClient("true", "true")
51 session, err := client.NewUploadPackSession(s.Endpoint, s.EmptyAuth)
52 c.Assert(err, IsNil)
53 ar, err := session.AdvertisedReferences()
54 c.Assert(err, IsNil)
55 c.Assert(ar, IsNil)
56 }
57
58 func (s *UploadPackSuite) TestMalformedInputNoErrors(c *C) {
59 if _, err := os.Stat("/usr/bin/yes"); os.IsNotExist(err) {
60 c.Skip("/usr/bin/yes not found")
61 }
62
63 client := NewClient("yes", "yes")
64 session, err := client.NewUploadPackSession(s.Endpoint, s.EmptyAuth)
65 c.Assert(err, IsNil)
66 ar, err := session.AdvertisedReferences()
67 c.Assert(err, NotNil)
68 c.Assert(ar, IsNil)
69 }
70
71 func (s *UploadPackSuite) TestNonExistentCommand(c *C) {
72 cmd := "/non-existent-git"
73 client := NewClient(cmd, cmd)
74 session, err := client.NewUploadPackSession(s.Endpoint, s.EmptyAuth)
75 // Error message is OS-dependant, so do a broad check
76 c.Assert(err, ErrorMatches, ".*file.*")
77 c.Assert(session, IsNil)
78 }
79
80 func (s *UploadPackSuite) TestUploadPackWithContextOnRead(c *C) {
81 // TODO: Fix race condition when Session.Close and the read failed due to a
82 // canceled context when the packfile is being read.
83 c.Skip("UploadPack has a race condition when we Close the session")
84 }