diff options
author | Antonio Jesus Navarro Perez <antnavper@gmail.com> | 2017-05-16 16:08:20 +0200 |
---|---|---|
committer | Antonio Jesus Navarro Perez <antnavper@gmail.com> | 2017-05-16 16:08:20 +0200 |
commit | 7e798fc34d703770e3391de8ecd65edea0d40181 (patch) | |
tree | f51f804ba5526e8990d0c1ce186e239667930600 | |
parent | 681f24d65046397228b4e4bb4e248fdb1e27f347 (diff) | |
download | go-git-7e798fc34d703770e3391de8ecd65edea0d40181.tar.gz |
transport/server: use Endpoint string representation as a map key.
Two endpoints are not equals between them, even if they were generated using the same url or path.
-rw-r--r-- | plumbing/transport/server/loader.go | 4 | ||||
-rw-r--r-- | plumbing/transport/server/loader_test.go | 16 | ||||
-rw-r--r-- | plumbing/transport/server/server_test.go | 4 |
3 files changed, 20 insertions, 4 deletions
diff --git a/plumbing/transport/server/loader.go b/plumbing/transport/server/loader.go index b51a795..386c2f0 100644 --- a/plumbing/transport/server/loader.go +++ b/plumbing/transport/server/loader.go @@ -44,13 +44,13 @@ func (l *fsLoader) Load(ep transport.Endpoint) (storer.Storer, error) { // MapLoader is a Loader that uses a lookup map of storer.Storer by // transport.Endpoint. -type MapLoader map[transport.Endpoint]storer.Storer +type MapLoader map[string]storer.Storer // Load returns a storer.Storer for given a transport.Endpoint by looking it up // in the map. Returns transport.ErrRepositoryNotFound if the endpoint does not // exist. func (l MapLoader) Load(ep transport.Endpoint) (storer.Storer, error) { - s, ok := l[ep] + s, ok := l[ep.String()] if !ok { return nil, transport.ErrRepositoryNotFound } diff --git a/plumbing/transport/server/loader_test.go b/plumbing/transport/server/loader_test.go index 5f32cb0..38fabe3 100644 --- a/plumbing/transport/server/loader_test.go +++ b/plumbing/transport/server/loader_test.go @@ -5,6 +5,7 @@ import ( "path/filepath" "gopkg.in/src-d/go-git.v4/plumbing/transport" + "gopkg.in/src-d/go-git.v4/storage/memory" . "gopkg.in/check.v1" ) @@ -54,3 +55,18 @@ func (s *LoaderSuite) TestLoadIgnoreHost(c *C) { c.Assert(err, IsNil) c.Assert(sto, NotNil) } + +func (s *LoaderSuite) TestMapLoader(c *C) { + ep, err := transport.NewEndpoint("file://test") + sto := memory.NewStorage() + c.Assert(err, IsNil) + + loader := MapLoader{ep.String(): sto} + + ep, err = transport.NewEndpoint("file://test") + c.Assert(err, IsNil) + + loaderSto, err := loader.Load(ep) + c.Assert(err, IsNil) + c.Assert(sto, Equals, loaderSto) +} diff --git a/plumbing/transport/server/server_test.go b/plumbing/transport/server/server_test.go index 2459ab2..6a64674 100644 --- a/plumbing/transport/server/server_test.go +++ b/plumbing/transport/server/server_test.go @@ -53,14 +53,14 @@ func (s *BaseSuite) prepareRepositories(c *C, basic *transport.Endpoint, *basic = ep sto, err := filesystem.NewStorage(fs) c.Assert(err, IsNil) - s.loader[ep] = sto + s.loader[ep.String()] = sto path = "/empty.git" url = fmt.Sprintf("%s://%s", inprocScheme, path) ep, err = transport.NewEndpoint(url) c.Assert(err, IsNil) *empty = ep - s.loader[ep] = memory.NewStorage() + s.loader[ep.String()] = memory.NewStorage() path = "/non-existent.git" url = fmt.Sprintf("%s://%s", inprocScheme, path) |