aboutsummaryrefslogtreecommitdiffstats
path: root/clients
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-02-11 12:09:02 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2016-02-11 12:09:02 +0100
commitd0155564148550167e756e440b5f9ce71c76abb3 (patch)
treecb6f7637286c8236997dc736133bbac4217d5e35 /clients
parent35ee4d749be21691b78a7465361ad47179fe2eff (diff)
downloadgo-git-d0155564148550167e756e440b5f9ce71c76abb3.tar.gz
clients: removing url from the clients constructor
Diffstat (limited to 'clients')
-rw-r--r--clients/common.go22
-rw-r--r--clients/common_test.go21
-rw-r--r--clients/http/git_upload_pack.go3
-rw-r--r--clients/http/git_upload_pack_test.go12
-rw-r--r--clients/ssh/git_upload_pack.go3
-rw-r--r--clients/ssh/git_upload_pack_test.go32
6 files changed, 47 insertions, 46 deletions
diff --git a/clients/common.go b/clients/common.go
index ce36dd1..24b3d63 100644
--- a/clients/common.go
+++ b/clients/common.go
@@ -28,16 +28,16 @@ type ServiceFromURLFunc func(url string) common.GitUploadPackService
// Wrapping is needed because you can not cast a function that
// returns an implementation of an interface to a function that
// returns the interface.
-var DefaultProtocols = map[string]ServiceFromURLFunc{
- "http": func(s string) common.GitUploadPackService { return http.NewGitUploadPackService(s) },
- "https": func(s string) common.GitUploadPackService { return http.NewGitUploadPackService(s) },
- "ssh": func(s string) common.GitUploadPackService { return ssh.NewGitUploadPackService(s) },
+var DefaultProtocols = map[string]common.GitUploadPackService{
+ "http": http.NewGitUploadPackService(),
+ "https": http.NewGitUploadPackService(),
+ "ssh": ssh.NewGitUploadPackService(),
}
// KnownProtocols holds the current set of known protocols. Initially
// it gets its contents from `DefaultProtocols`. See `InstallProtocol`
// below to add or modify this variable.
-var KnownProtocols = make(map[string]ServiceFromURLFunc, len(DefaultProtocols))
+var KnownProtocols = make(map[string]common.GitUploadPackService, len(DefaultProtocols))
func init() {
for k, v := range DefaultProtocols {
@@ -53,17 +53,19 @@ func NewGitUploadPackService(repoURL string) (common.GitUploadPackService, error
if err != nil {
return nil, fmt.Errorf("invalid url %q", repoURL)
}
- srvFn, ok := KnownProtocols[u.Scheme]
+ service, ok := KnownProtocols[u.Scheme]
if !ok {
return nil, fmt.Errorf("unsupported scheme %q", u.Scheme)
}
- return srvFn(repoURL), nil
+
+ return service, nil
}
// InstallProtocol adds or modifies an existing protocol.
-func InstallProtocol(scheme string, serviceFn ServiceFromURLFunc) {
- if serviceFn == nil {
+func InstallProtocol(scheme string, service common.GitUploadPackService) {
+ if service == nil {
panic("nil service")
}
- KnownProtocols[scheme] = serviceFn
+
+ KnownProtocols[scheme] = service
}
diff --git a/clients/common_test.go b/clients/common_test.go
index ff9ca32..c3b766b 100644
--- a/clients/common_test.go
+++ b/clients/common_test.go
@@ -37,7 +37,7 @@ func (s *SuiteCommon) TestNewGitUploadPackService(c *C) {
type dummyProtocolService struct{}
-func newDummyProtocolService(url string) common.GitUploadPackService {
+func newDummyProtocolService() common.GitUploadPackService {
return &dummyProtocolService{}
}
@@ -59,23 +59,24 @@ func (s *dummyProtocolService) Fetch(r *common.GitUploadPackRequest) (io.ReadClo
func (s *SuiteCommon) TestInstallProtocol(c *C) {
var tests = [...]struct {
- scheme string
- serviceFn ServiceFromURLFunc
- panic bool
+ scheme string
+ service common.GitUploadPackService
+ panic bool
}{
{"panic", nil, true},
- {"newscheme", newDummyProtocolService, false},
- {"http", newDummyProtocolService, false},
+ {"newscheme", newDummyProtocolService(), false},
+ {"http", newDummyProtocolService(), false},
}
for i, t := range tests {
if t.panic {
- fmt.Println(t.serviceFn == nil)
- c.Assert(func() { InstallProtocol(t.scheme, t.serviceFn) }, PanicMatches, `nil service`)
+ fmt.Println(t.service == nil)
+ c.Assert(func() { InstallProtocol(t.scheme, t.service) }, PanicMatches, `nil service`)
continue
}
- InstallProtocol(t.scheme, t.serviceFn)
- c.Assert(typeAsString(KnownProtocols[t.scheme]), Equals, typeAsString(t.serviceFn), Commentf("%d) wrong service", i))
+
+ InstallProtocol(t.scheme, t.service)
+ c.Assert(typeAsString(KnownProtocols[t.scheme]), Equals, typeAsString(t.service), Commentf("%d) wrong service", i))
// reset to default protocols after installing
if v, ok := DefaultProtocols[t.scheme]; ok {
InstallProtocol(t.scheme, v)
diff --git a/clients/http/git_upload_pack.go b/clients/http/git_upload_pack.go
index 4b06c72..2d38d42 100644
--- a/clients/http/git_upload_pack.go
+++ b/clients/http/git_upload_pack.go
@@ -18,8 +18,7 @@ type GitUploadPackService struct {
auth HTTPAuthMethod
}
-func NewGitUploadPackService(url string) *GitUploadPackService {
- // url ignored
+func NewGitUploadPackService() *GitUploadPackService {
return &GitUploadPackService{
Client: http.DefaultClient,
}
diff --git a/clients/http/git_upload_pack_test.go b/clients/http/git_upload_pack_test.go
index b479155..f9ec424 100644
--- a/clients/http/git_upload_pack_test.go
+++ b/clients/http/git_upload_pack_test.go
@@ -15,13 +15,13 @@ var _ = Suite(&SuiteRemote{})
const RepositoryFixture = "https://github.com/tyba/git-fixture"
func (s *SuiteRemote) TestConnect(c *C) {
- r := NewGitUploadPackService(RepositoryFixture)
+ r := NewGitUploadPackService()
c.Assert(r.Connect(RepositoryFixture), IsNil)
}
func (s *SuiteRemote) TestConnectWithAuth(c *C) {
auth := &BasicAuth{}
- r := NewGitUploadPackService(RepositoryFixture)
+ r := NewGitUploadPackService()
c.Assert(r.ConnectWithAuth(RepositoryFixture, auth), IsNil)
c.Assert(r.auth, Equals, auth)
}
@@ -32,12 +32,12 @@ func (*mockAuth) Name() string { return "" }
func (*mockAuth) String() string { return "" }
func (s *SuiteRemote) TestConnectWithAuthWrongType(c *C) {
- r := NewGitUploadPackService(RepositoryFixture)
+ r := NewGitUploadPackService()
c.Assert(r.ConnectWithAuth(RepositoryFixture, &mockAuth{}), Equals, InvalidAuthMethodErr)
}
func (s *SuiteRemote) TestDefaultBranch(c *C) {
- r := NewGitUploadPackService(RepositoryFixture)
+ r := NewGitUploadPackService()
c.Assert(r.Connect(RepositoryFixture), IsNil)
info, err := r.Info()
@@ -46,7 +46,7 @@ func (s *SuiteRemote) TestDefaultBranch(c *C) {
}
func (s *SuiteRemote) TestCapabilities(c *C) {
- r := NewGitUploadPackService(RepositoryFixture)
+ r := NewGitUploadPackService()
c.Assert(r.Connect(RepositoryFixture), IsNil)
info, err := r.Info()
@@ -55,7 +55,7 @@ func (s *SuiteRemote) TestCapabilities(c *C) {
}
func (s *SuiteRemote) TestFetch(c *C) {
- r := NewGitUploadPackService(RepositoryFixture)
+ r := NewGitUploadPackService()
c.Assert(r.Connect(RepositoryFixture), IsNil)
req := &common.GitUploadPackRequest{}
diff --git a/clients/ssh/git_upload_pack.go b/clients/ssh/git_upload_pack.go
index 4a4021d..09cb5ab 100644
--- a/clients/ssh/git_upload_pack.go
+++ b/clients/ssh/git_upload_pack.go
@@ -42,8 +42,7 @@ type GitUploadPackService struct {
// NewGitUploadPackService initialises a GitUploadPackService.
// TODO: remove this, as the struct is zero-value safe.
-func NewGitUploadPackService(url string) *GitUploadPackService {
- // url ignored
+func NewGitUploadPackService() *GitUploadPackService {
return &GitUploadPackService{}
}
diff --git a/clients/ssh/git_upload_pack_test.go b/clients/ssh/git_upload_pack_test.go
index 8626b50..66ac306 100644
--- a/clients/ssh/git_upload_pack_test.go
+++ b/clients/ssh/git_upload_pack_test.go
@@ -25,7 +25,7 @@ const (
)
func (s *SuiteRemote) TestConnect(c *C) {
- r := NewGitUploadPackService(fixRepo)
+ r := NewGitUploadPackService()
c.Assert(r.Connect(fixRepo), Equals, ErrAuthRequired)
}
@@ -62,7 +62,7 @@ func (s *SuiteRemote) TestConnectWithPublicKeysCallback(c *C) {
c.Assert(err, IsNil)
defer func() { c.Assert(agent.close(), IsNil) }()
- r := NewGitUploadPackService(fixRepo)
+ r := NewGitUploadPackService()
c.Assert(r.ConnectWithAuth(fixRepo, agent.auth), IsNil)
defer func() { c.Assert(r.Disconnect(), IsNil) }()
c.Assert(r.connected, Equals, true)
@@ -70,17 +70,17 @@ func (s *SuiteRemote) TestConnectWithPublicKeysCallback(c *C) {
}
func (s *SuiteRemote) TestConnectBadVcs(c *C) {
- r := NewGitUploadPackService(fixRepoBadVcs)
+ r := NewGitUploadPackService()
c.Assert(r.ConnectWithAuth(fixRepoBadVcs, nil), ErrorMatches, fmt.Sprintf(".*%s.*", fixRepoBadVcs))
}
func (s *SuiteRemote) TestConnectNonGit(c *C) {
- r := NewGitUploadPackService(fixRepoNonGit)
+ r := NewGitUploadPackService()
c.Assert(r.ConnectWithAuth(fixRepoNonGit, nil), Equals, ErrUnsupportedVCS)
}
func (s *SuiteRemote) TestConnectNonGithub(c *C) {
- r := NewGitUploadPackService(fixGitRepoNonGithub)
+ r := NewGitUploadPackService()
c.Assert(r.ConnectWithAuth(fixGitRepoNonGithub, nil), Equals, ErrUnsupportedRepo)
}
@@ -92,7 +92,7 @@ func (*mockAuth) Name() string { return "" }
func (*mockAuth) String() string { return "" }
func (s *SuiteRemote) TestConnectWithAuthWrongType(c *C) {
- r := NewGitUploadPackService(fixRepo)
+ r := NewGitUploadPackService()
c.Assert(r.ConnectWithAuth(fixRepo, &mockAuth{}), Equals, ErrInvalidAuthMethod)
c.Assert(r.connected, Equals, false)
}
@@ -102,7 +102,7 @@ func (s *SuiteRemote) TestAlreadyConnected(c *C) {
c.Assert(err, IsNil)
defer func() { c.Assert(agent.close(), IsNil) }()
- r := NewGitUploadPackService(fixRepo)
+ r := NewGitUploadPackService()
c.Assert(r.ConnectWithAuth(fixRepo, agent.auth), IsNil)
defer func() { c.Assert(r.Disconnect(), IsNil) }()
c.Assert(r.ConnectWithAuth(fixRepo, agent.auth), Equals, ErrAlreadyConnected)
@@ -114,14 +114,14 @@ func (s *SuiteRemote) TestDisconnect(c *C) {
c.Assert(err, IsNil)
defer func() { c.Assert(agent.close(), IsNil) }()
- r := NewGitUploadPackService(fixRepo)
+ r := NewGitUploadPackService()
c.Assert(r.ConnectWithAuth(fixRepo, agent.auth), IsNil)
c.Assert(r.Disconnect(), IsNil)
c.Assert(r.connected, Equals, false)
}
func (s *SuiteRemote) TestDisconnectedWhenNonConnected(c *C) {
- r := NewGitUploadPackService("Dear Twinkle")
+ r := NewGitUploadPackService()
c.Assert(r.Disconnect(), Equals, ErrNotConnected)
}
@@ -130,7 +130,7 @@ func (s *SuiteRemote) TestAlreadyDisconnected(c *C) {
c.Assert(err, IsNil)
defer func() { c.Assert(agent.close(), IsNil) }()
- r := NewGitUploadPackService(fixRepo)
+ r := NewGitUploadPackService()
c.Assert(r.ConnectWithAuth(fixRepo, agent.auth), IsNil)
c.Assert(r.Disconnect(), IsNil)
c.Assert(r.Disconnect(), Equals, ErrNotConnected)
@@ -142,7 +142,7 @@ func (s *SuiteRemote) TestServeralConnections(c *C) {
c.Assert(err, IsNil)
defer func() { c.Assert(agent.close(), IsNil) }()
- r := NewGitUploadPackService(fixRepo)
+ r := NewGitUploadPackService()
c.Assert(r.ConnectWithAuth(fixRepo, agent.auth), IsNil)
c.Assert(r.Disconnect(), IsNil)
@@ -158,7 +158,7 @@ func (s *SuiteRemote) TestServeralConnections(c *C) {
}
func (s *SuiteRemote) TestInfoNotConnected(c *C) {
- r := NewGitUploadPackService(fixRepo)
+ r := NewGitUploadPackService()
_, err := r.Info()
c.Assert(err, Equals, ErrNotConnected)
}
@@ -168,7 +168,7 @@ func (s *SuiteRemote) TestDefaultBranch(c *C) {
c.Assert(err, IsNil)
defer func() { c.Assert(agent.close(), IsNil) }()
- r := NewGitUploadPackService(fixRepo)
+ r := NewGitUploadPackService()
c.Assert(r.ConnectWithAuth(fixRepo, agent.auth), IsNil)
defer func() { c.Assert(r.Disconnect(), IsNil) }()
@@ -182,7 +182,7 @@ func (s *SuiteRemote) TestCapabilities(c *C) {
c.Assert(err, IsNil)
defer func() { c.Assert(agent.close(), IsNil) }()
- r := NewGitUploadPackService(fixRepo)
+ r := NewGitUploadPackService()
c.Assert(r.ConnectWithAuth(fixRepo, agent.auth), IsNil)
defer func() { c.Assert(r.Disconnect(), IsNil) }()
@@ -192,7 +192,7 @@ func (s *SuiteRemote) TestCapabilities(c *C) {
}
func (s *SuiteRemote) TestFetchNotConnected(c *C) {
- r := NewGitUploadPackService("foo bar")
+ r := NewGitUploadPackService()
pr := &common.GitUploadPackRequest{}
pr.Want(core.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"))
_, err := r.Fetch(pr)
@@ -204,7 +204,7 @@ func (s *SuiteRemote) TestFetch(c *C) {
c.Assert(err, IsNil)
defer func() { c.Assert(agent.close(), IsNil) }()
- r := NewGitUploadPackService(fixRepo)
+ r := NewGitUploadPackService()
c.Assert(r.ConnectWithAuth(fixRepo, agent.auth), IsNil)
defer func() { c.Assert(r.Disconnect(), IsNil) }()