diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2017-11-21 08:43:11 +0100 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2017-11-21 08:43:11 +0100 |
commit | 5eb1c562e7deb4191cb160af91a864fb783c1041 (patch) | |
tree | 090b3fef25c728381f384f9e04a86fa9905549c8 /plumbing/transport/server | |
parent | 90796406c0755f61761fb176cdfe6106f00d903c (diff) | |
download | go-git-5eb1c562e7deb4191cb160af91a864fb783c1041.tar.gz |
*: add pointer to the new transport.Endpoint struct
Signed-off-by: Máximo Cuadros <mcuadros@gmail.com>
Diffstat (limited to 'plumbing/transport/server')
-rw-r--r-- | plumbing/transport/server/loader.go | 8 | ||||
-rw-r--r-- | plumbing/transport/server/loader_test.go | 2 | ||||
-rw-r--r-- | plumbing/transport/server/receive_pack_test.go | 4 | ||||
-rw-r--r-- | plumbing/transport/server/server.go | 4 | ||||
-rw-r--r-- | plumbing/transport/server/server_test.go | 27 | ||||
-rw-r--r-- | plumbing/transport/server/upload_pack_test.go | 17 |
6 files changed, 22 insertions, 40 deletions
diff --git a/plumbing/transport/server/loader.go b/plumbing/transport/server/loader.go index 028ead4..3af55e1 100644 --- a/plumbing/transport/server/loader.go +++ b/plumbing/transport/server/loader.go @@ -17,7 +17,7 @@ type Loader interface { // Load loads a storer.Storer given a transport.Endpoint. // Returns transport.ErrRepositoryNotFound if the repository does not // exist. - Load(ep transport.Endpoint) (storer.Storer, error) + Load(ep *transport.Endpoint) (storer.Storer, error) } type fsLoader struct { @@ -33,8 +33,8 @@ func NewFilesystemLoader(base billy.Filesystem) Loader { // Load looks up the endpoint's path in the base file system and returns a // storer for it. Returns transport.ErrRepositoryNotFound if a repository does // not exist in the given path. -func (l *fsLoader) Load(ep transport.Endpoint) (storer.Storer, error) { - fs, err := l.base.Chroot(ep.Path()) +func (l *fsLoader) Load(ep *transport.Endpoint) (storer.Storer, error) { + fs, err := l.base.Chroot(ep.Path) if err != nil { return nil, err } @@ -53,7 +53,7 @@ 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) { +func (l MapLoader) Load(ep *transport.Endpoint) (storer.Storer, error) { 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 38fabe3..f35511d 100644 --- a/plumbing/transport/server/loader_test.go +++ b/plumbing/transport/server/loader_test.go @@ -26,7 +26,7 @@ func (s *LoaderSuite) SetUpSuite(c *C) { c.Assert(exec.Command("git", "init", "--bare", s.RepoPath).Run(), IsNil) } -func (s *LoaderSuite) endpoint(c *C, url string) transport.Endpoint { +func (s *LoaderSuite) endpoint(c *C, url string) *transport.Endpoint { ep, err := transport.NewEndpoint(url) c.Assert(err, IsNil) return ep diff --git a/plumbing/transport/server/receive_pack_test.go b/plumbing/transport/server/receive_pack_test.go index 54c2fba..39fa979 100644 --- a/plumbing/transport/server/receive_pack_test.go +++ b/plumbing/transport/server/receive_pack_test.go @@ -2,14 +2,12 @@ package server_test import ( "gopkg.in/src-d/go-git.v4/plumbing/transport" - "gopkg.in/src-d/go-git.v4/plumbing/transport/test" . "gopkg.in/check.v1" ) type ReceivePackSuite struct { BaseSuite - test.ReceivePackSuite } var _ = Suite(&ReceivePackSuite{}) @@ -20,7 +18,7 @@ func (s *ReceivePackSuite) SetUpSuite(c *C) { } func (s *ReceivePackSuite) SetUpTest(c *C) { - s.prepareRepositories(c, &s.Endpoint, &s.EmptyEndpoint, &s.NonExistentEndpoint) + s.prepareRepositories(c) } func (s *ReceivePackSuite) TearDownTest(c *C) { diff --git a/plumbing/transport/server/server.go b/plumbing/transport/server/server.go index f896f7a..2357bd6 100644 --- a/plumbing/transport/server/server.go +++ b/plumbing/transport/server/server.go @@ -43,7 +43,7 @@ func NewClient(loader Loader) transport.Transport { } } -func (s *server) NewUploadPackSession(ep transport.Endpoint, auth transport.AuthMethod) (transport.UploadPackSession, error) { +func (s *server) NewUploadPackSession(ep *transport.Endpoint, auth transport.AuthMethod) (transport.UploadPackSession, error) { sto, err := s.loader.Load(ep) if err != nil { return nil, err @@ -52,7 +52,7 @@ func (s *server) NewUploadPackSession(ep transport.Endpoint, auth transport.Auth return s.handler.NewUploadPackSession(sto) } -func (s *server) NewReceivePackSession(ep transport.Endpoint, auth transport.AuthMethod) (transport.ReceivePackSession, error) { +func (s *server) NewReceivePackSession(ep *transport.Endpoint, auth transport.AuthMethod) (transport.ReceivePackSession, error) { sto, err := s.loader.Load(ep) if err != nil { return nil, err diff --git a/plumbing/transport/server/server_test.go b/plumbing/transport/server/server_test.go index 7912768..335aeae 100644 --- a/plumbing/transport/server/server_test.go +++ b/plumbing/transport/server/server_test.go @@ -7,6 +7,7 @@ import ( "gopkg.in/src-d/go-git.v4/plumbing/transport" "gopkg.in/src-d/go-git.v4/plumbing/transport/client" "gopkg.in/src-d/go-git.v4/plumbing/transport/server" + "gopkg.in/src-d/go-git.v4/plumbing/transport/test" "gopkg.in/src-d/go-git.v4/storage/filesystem" "gopkg.in/src-d/go-git.v4/storage/memory" @@ -17,6 +18,8 @@ func Test(t *testing.T) { TestingT(t) } type BaseSuite struct { fixtures.Suite + test.ReceivePackSuite + loader server.MapLoader client transport.Transport clientBackup transport.Transport @@ -44,27 +47,19 @@ func (s *BaseSuite) TearDownSuite(c *C) { } } -func (s *BaseSuite) prepareRepositories(c *C, basic *transport.Endpoint, - empty *transport.Endpoint, nonExistent *transport.Endpoint) { +func (s *BaseSuite) prepareRepositories(c *C) { + var err error - f := fixtures.Basic().One() - fs := f.DotGit() - path := fs.Root() - ep, err := transport.NewEndpoint(path) + fs := fixtures.Basic().One().DotGit() + s.Endpoint, err = transport.NewEndpoint(fs.Root()) c.Assert(err, IsNil) - *basic = ep - sto, err := filesystem.NewStorage(fs) + s.loader[s.Endpoint.String()], err = filesystem.NewStorage(fs) c.Assert(err, IsNil) - s.loader[ep.String()] = sto - path = "/empty.git" - ep, err = transport.NewEndpoint(path) + s.EmptyEndpoint, err = transport.NewEndpoint("/empty.git") c.Assert(err, IsNil) - *empty = ep - s.loader[ep.String()] = memory.NewStorage() + s.loader[s.EmptyEndpoint.String()] = memory.NewStorage() - path = "/non-existent.git" - ep, err = transport.NewEndpoint(path) + s.NonExistentEndpoint, err = transport.NewEndpoint("/non-existent.git") c.Assert(err, IsNil) - *nonExistent = ep } diff --git a/plumbing/transport/server/upload_pack_test.go b/plumbing/transport/server/upload_pack_test.go index 99473d3..f252a75 100644 --- a/plumbing/transport/server/upload_pack_test.go +++ b/plumbing/transport/server/upload_pack_test.go @@ -2,34 +2,23 @@ package server_test import ( "gopkg.in/src-d/go-git.v4/plumbing/transport" - "gopkg.in/src-d/go-git.v4/plumbing/transport/test" . "gopkg.in/check.v1" ) type UploadPackSuite struct { BaseSuite - test.UploadPackSuite } var _ = Suite(&UploadPackSuite{}) func (s *UploadPackSuite) SetUpSuite(c *C) { s.BaseSuite.SetUpSuite(c) - s.UploadPackSuite.Client = s.client + s.Client = s.client } func (s *UploadPackSuite) SetUpTest(c *C) { - s.prepareRepositories(c, &s.Endpoint, &s.EmptyEndpoint, &s.NonExistentEndpoint) -} - -// Overwritten, it's not an error in server-side. -func (s *UploadPackSuite) TestAdvertisedReferencesEmpty(c *C) { - r, err := s.Client.NewUploadPackSession(s.EmptyEndpoint, s.EmptyAuth) - c.Assert(err, IsNil) - ar, err := r.AdvertisedReferences() - c.Assert(err, IsNil) - c.Assert(len(ar.References), Equals, 0) + s.prepareRepositories(c) } // Overwritten, server returns error earlier. @@ -57,5 +46,5 @@ func (s *ClientLikeUploadPackSuite) SetUpSuite(c *C) { } func (s *ClientLikeUploadPackSuite) TestAdvertisedReferencesEmpty(c *C) { - s.UploadPackSuite.UploadPackSuite.TestAdvertisedReferencesEmpty(c) + s.UploadPackSuite.TestAdvertisedReferencesEmpty(c) } |