diff options
-rw-r--r-- | common_test.go | 12 | ||||
-rw-r--r-- | plumbing/object/file_test.go | 5 | ||||
-rw-r--r-- | plumbing/object/tree_test.go | 5 | ||||
-rw-r--r-- | plumbing/transport/client/client.go | 9 | ||||
-rw-r--r-- | plumbing/transport/client/client_test.go | 33 |
5 files changed, 32 insertions, 32 deletions
diff --git a/common_test.go b/common_test.go index 5aabd06..98c81b1 100644 --- a/common_test.go +++ b/common_test.go @@ -7,7 +7,6 @@ import ( "srcd.works/go-git.v4/plumbing" "srcd.works/go-git.v4/plumbing/format/packfile" "srcd.works/go-git.v4/plumbing/transport" - "srcd.works/go-git.v4/plumbing/transport/client" "srcd.works/go-git.v4/storage/filesystem" "srcd.works/go-git.v4/storage/memory" @@ -29,7 +28,6 @@ type BaseSuite struct { func (s *BaseSuite) SetUpSuite(c *C) { s.Suite.SetUpSuite(c) - s.installMockProtocol() s.buildBasicRepository(c) s.cache = make(map[string]*Repository, 0) @@ -37,7 +35,6 @@ func (s *BaseSuite) SetUpSuite(c *C) { func (s *BaseSuite) TearDownSuite(c *C) { s.Suite.TearDownSuite(c) - s.uninstallMockProtocol() } func (s *BaseSuite) buildBasicRepository(c *C) { @@ -92,15 +89,6 @@ func (s *BaseSuite) NewRepositoryFromPackfile(f *fixtures.Fixture) *Repository { return r } -func (s *BaseSuite) installMockProtocol() { - s.backupProtocol = client.Protocols["https"] - client.InstallProtocol("https", nil) -} - -func (s *BaseSuite) uninstallMockProtocol() { - client.InstallProtocol("https", s.backupProtocol) -} - func (s *BaseSuite) GetBasicLocalRepositoryURL() string { fixture := fixtures.Basic().One() return s.GetLocalRepositoryURL(fixture) diff --git a/plumbing/object/file_test.go b/plumbing/object/file_test.go index ff01c9f..c482541 100644 --- a/plumbing/object/file_test.go +++ b/plumbing/object/file_test.go @@ -254,7 +254,7 @@ func (s *FileSuite) TestFileIterSubmodule(c *C) { c.Assert(err, IsNil) - hash := plumbing.NewHash("a692ec699bff9117c1ed91752afbb7d9d272ebef") + hash := plumbing.NewHash("b685400c1f9316f350965a5993d350bc746b0bf4") commit, err := GetCommit(st, hash) c.Assert(err, IsNil) @@ -263,6 +263,7 @@ func (s *FileSuite) TestFileIterSubmodule(c *C) { expected := []string{ ".gitmodules", + "README.md", } var count int @@ -273,5 +274,5 @@ func (s *FileSuite) TestFileIterSubmodule(c *C) { return nil }) - c.Assert(count, Equals, 1) + c.Assert(count, Equals, 2) } diff --git a/plumbing/object/tree_test.go b/plumbing/object/tree_test.go index 8ea31bb..81fbdec 100644 --- a/plumbing/object/tree_test.go +++ b/plumbing/object/tree_test.go @@ -270,7 +270,7 @@ func (s *TreeSuite) TestTreeWalkerNextSubmodule(c *C) { st, err := filesystem.NewStorage(dotgit) c.Assert(err, IsNil) - hash := plumbing.NewHash("a692ec699bff9117c1ed91752afbb7d9d272ebef") + hash := plumbing.NewHash("b685400c1f9316f350965a5993d350bc746b0bf4") commit, err := GetCommit(st, hash) c.Assert(err, IsNil) @@ -279,6 +279,7 @@ func (s *TreeSuite) TestTreeWalkerNextSubmodule(c *C) { expected := []string{ ".gitmodules", + "README.md", "basic", "itself", } @@ -300,7 +301,7 @@ func (s *TreeSuite) TestTreeWalkerNextSubmodule(c *C) { count++ } - c.Assert(count, Equals, 3) + c.Assert(count, Equals, 4) } var treeWalkerExpects = []struct { diff --git a/plumbing/transport/client/client.go b/plumbing/transport/client/client.go index f749875..ea1e034 100644 --- a/plumbing/transport/client/client.go +++ b/plumbing/transport/client/client.go @@ -23,6 +23,11 @@ var Protocols = map[string]transport.Transport{ // InstallProtocol adds or modifies an existing protocol. func InstallProtocol(scheme string, c transport.Transport) { + if c == nil { + delete(Protocols, scheme) + return + } + Protocols[scheme] = c } @@ -35,5 +40,9 @@ func NewClient(endpoint transport.Endpoint) (transport.Transport, error) { return nil, fmt.Errorf("unsupported scheme %q", endpoint.Scheme) } + if f == nil { + return nil, fmt.Errorf("malformed client for scheme %q, client is defined as nil", endpoint.Scheme) + } + return f, nil } diff --git a/plumbing/transport/client/client_test.go b/plumbing/transport/client/client_test.go index a3715d2..0377d34 100644 --- a/plumbing/transport/client/client_test.go +++ b/plumbing/transport/client/client_test.go @@ -16,22 +16,6 @@ type ClientSuite struct{} var _ = Suite(&ClientSuite{}) -func (s *ClientSuite) TestNewClientHTTP(c *C) { - e, err := transport.NewEndpoint("http://github.com/src-d/go-git") - c.Assert(err, IsNil) - - output, err := NewClient(e) - c.Assert(err, IsNil) - c.Assert(typeAsString(output), Equals, "*http.client") - - e, err = transport.NewEndpoint("https://github.com/src-d/go-git") - c.Assert(err, IsNil) - - output, err = NewClient(e) - c.Assert(err, IsNil) - c.Assert(typeAsString(output), Equals, "*http.client") -} - func (s *ClientSuite) TestNewClientSSH(c *C) { e, err := transport.NewEndpoint("ssh://github.com/src-d/go-git") c.Assert(err, IsNil) @@ -49,11 +33,28 @@ func (s *ClientSuite) TestNewClientUnknown(c *C) { c.Assert(err, NotNil) } +func (s *ClientSuite) TestNewClientNil(c *C) { + Protocols["newscheme"] = nil + e, err := transport.NewEndpoint("newscheme://github.com/src-d/go-git") + c.Assert(err, IsNil) + + _, err = NewClient(e) + c.Assert(err, NotNil) +} + func (s *ClientSuite) TestInstallProtocol(c *C) { InstallProtocol("newscheme", &dummyClient{}) c.Assert(Protocols["newscheme"], NotNil) } +func (s *ClientSuite) TestInstallProtocolNilValue(c *C) { + InstallProtocol("newscheme", &dummyClient{}) + InstallProtocol("newscheme", nil) + + _, ok := Protocols["newscheme"] + c.Assert(ok, Equals, false) +} + type dummyClient struct { *http.Client } |