Debian Codegraph @

plumbing/transport/client/client_test.go

raw
1 package client
2
3 import (
4 "net/http"
5 "testing"
6
7 "github.com/go-git/go-git/v5/plumbing/transport"
8
9 . "gopkg.in/check.v1"
10 )
11
12 func Test(t *testing.T) { TestingT(t) }
13
14 type ClientSuite struct{}
15
16 var _ = Suite(&ClientSuite{})
17
18 func (s *ClientSuite) TestNewClientSSH(c *C) {
19 e, err := transport.NewEndpoint("ssh://github.com/src-d/go-git")
20 c.Assert(err, IsNil)
21
22 output, err := NewClient(e)
23 c.Assert(err, IsNil)
24 c.Assert(output, NotNil)
25 }
26
27 func (s *ClientSuite) TestNewClientUnknown(c *C) {
28 e, err := transport.NewEndpoint("unknown://github.com/src-d/go-git")
29 c.Assert(err, IsNil)
30
31 _, err = NewClient(e)
32 c.Assert(err, NotNil)
33 }
34
35 func (s *ClientSuite) TestNewClientNil(c *C) {
36 Protocols["newscheme"] = nil
37 e, err := transport.NewEndpoint("newscheme://github.com/src-d/go-git")
38 c.Assert(err, IsNil)
39
40 _, err = NewClient(e)
41 c.Assert(err, NotNil)
42 }
43
44 func (s *ClientSuite) TestInstallProtocol(c *C) {
45 InstallProtocol("newscheme", &dummyClient{})
46 c.Assert(Protocols["newscheme"], NotNil)
47 }
48
49 func (s *ClientSuite) TestInstallProtocolNilValue(c *C) {
50 InstallProtocol("newscheme", &dummyClient{})
51 InstallProtocol("newscheme", nil)
52
53 _, ok := Protocols["newscheme"]
54 c.Assert(ok, Equals, false)
55 }
56
57 type dummyClient struct {
58 *http.Client
59 }
60
61 func (*dummyClient) NewUploadPackSession(*transport.Endpoint, transport.AuthMethod) (
62 transport.UploadPackSession, error) {
63 return nil, nil
64 }
65
66 func (*dummyClient) NewReceivePackSession(*transport.Endpoint, transport.AuthMethod) (
67 transport.ReceivePackSession, error) {
68 return nil, nil
69 }