aboutsummaryrefslogtreecommitdiffstats
path: root/common_test.go
diff options
context:
space:
mode:
authorSantiago M. Mola <santi@mola.io>2016-11-23 15:30:34 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2016-11-23 15:38:12 +0100
commit08e08d771ef03df80248c80d81475fe7c5ea6fe7 (patch)
treed12e9befa22409e8cf50c5bbc4895e69fd8a5f48 /common_test.go
parent844169a739fb8bf1f252d416f10d8c7034db9fe2 (diff)
downloadgo-git-08e08d771ef03df80248c80d81475fe7c5ea6fe7.tar.gz
transport: create Client interface (#132)
* plumbing: move plumbing/client package to plumbing/transport. * transport: create Client interface. * A Client can instantiate any client transport service. * InstallProtocol installs a Client for a given protocol, instead of just a UploadPackService. * A Client can open a session for fetch-pack or send-pack for a specific Endpoint. * Adapt ssh and http clients to the new client interface. * updated doc
Diffstat (limited to 'common_test.go')
-rw-r--r--common_test.go66
1 files changed, 35 insertions, 31 deletions
diff --git a/common_test.go b/common_test.go
index 95282ea..fed5301 100644
--- a/common_test.go
+++ b/common_test.go
@@ -1,17 +1,17 @@
package git
import (
- "errors"
+ "fmt"
"io"
"os"
"testing"
"gopkg.in/src-d/go-git.v4/fixtures"
"gopkg.in/src-d/go-git.v4/plumbing"
- "gopkg.in/src-d/go-git.v4/plumbing/client"
- "gopkg.in/src-d/go-git.v4/plumbing/client/common"
"gopkg.in/src-d/go-git.v4/plumbing/format/packfile"
"gopkg.in/src-d/go-git.v4/plumbing/format/packp"
+ "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/storage/filesystem"
. "gopkg.in/check.v1"
@@ -36,9 +36,7 @@ func (s *BaseSuite) SetUpSuite(c *C) {
}
func (s *BaseSuite) installMockProtocol(c *C) {
- clients.InstallProtocol("https", func(end common.Endpoint) common.GitUploadPackService {
- return &MockGitUploadPackService{endpoint: end}
- })
+ client.InstallProtocol("https", &MockClient{})
}
func (s *BaseSuite) buildRepository(c *C) {
@@ -68,38 +66,47 @@ func (s *BaseSuite) buildRepositories(c *C, f fixtures.Fixtures) {
const RepositoryFixture = "https://github.com/git-fixtures/basic.git"
-type MockGitUploadPackService struct {
- connected bool
- endpoint common.Endpoint
- auth common.AuthMethod
+type MockClient struct{}
+
+type MockFetchPackSession struct {
+ endpoint transport.Endpoint
+ auth transport.AuthMethod
}
-func (p *MockGitUploadPackService) Connect() error {
- p.connected = true
- return nil
+func (c *MockClient) NewFetchPackSession(ep transport.Endpoint) (
+ transport.FetchPackSession, error) {
+
+ return &MockFetchPackSession{
+ endpoint: ep,
+ auth: nil,
+ }, nil
}
-func (p *MockGitUploadPackService) SetAuth(auth common.AuthMethod) error {
- p.auth = auth
+func (c *MockClient) NewSendPackSession(ep transport.Endpoint) (
+ transport.SendPackSession, error) {
+
+ return nil, fmt.Errorf("not supported")
+}
+
+func (c *MockFetchPackSession) SetAuth(auth transport.AuthMethod) error {
+ c.auth = auth
return nil
}
-func (p *MockGitUploadPackService) Info() (*common.GitUploadPackInfo, error) {
- if !p.connected {
- return nil, errors.New("not connected")
- }
+func (c *MockFetchPackSession) AdvertisedReferences() (
+ *transport.UploadPackInfo, error) {
- h := fixtures.ByURL(p.endpoint.String()).One().Head
+ h := fixtures.ByURL(c.endpoint.String()).One().Head
- c := packp.NewCapabilities()
- c.Decode("6ecf0ef2c2dffb796033e5a02219af86ec6584e5 HEADmulti_ack thin-pack side-band side-band-64k ofs-delta shallow no-progress include-tag multi_ack_detailed no-done symref=HEAD:refs/heads/master agent=git/2:2.4.8~dbussink-fix-enterprise-tokens-compilation-1167-gc7006cf")
+ cap := packp.NewCapabilities()
+ cap.Decode("6ecf0ef2c2dffb796033e5a02219af86ec6584e5 HEADmulti_ack thin-pack side-band side-band-64k ofs-delta shallow no-progress include-tag multi_ack_detailed no-done symref=HEAD:refs/heads/master agent=git/2:2.4.8~dbussink-fix-enterprise-tokens-compilation-1167-gc7006cf")
ref := plumbing.ReferenceName("refs/heads/master")
branch := plumbing.ReferenceName("refs/heads/branch")
tag := plumbing.ReferenceName("refs/tags/v1.0.0")
- return &common.GitUploadPackInfo{
- Capabilities: c,
+ return &transport.UploadPackInfo{
+ Capabilities: cap,
Refs: map[plumbing.ReferenceName]*plumbing.Reference{
plumbing.HEAD: plumbing.NewSymbolicReference(plumbing.HEAD, ref),
ref: plumbing.NewHashReference(ref, h),
@@ -109,12 +116,10 @@ func (p *MockGitUploadPackService) Info() (*common.GitUploadPackInfo, error) {
}, nil
}
-func (p *MockGitUploadPackService) Fetch(r *common.GitUploadPackRequest) (io.ReadCloser, error) {
- if !p.connected {
- return nil, errors.New("not connected")
- }
+func (c *MockFetchPackSession) FetchPack(
+ r *transport.UploadPackRequest) (io.ReadCloser, error) {
- f := fixtures.ByURL(p.endpoint.String())
+ f := fixtures.ByURL(c.endpoint.String())
if len(r.Wants) == 1 {
return f.Exclude("single-branch").One().Packfile(), nil
@@ -123,8 +128,7 @@ func (p *MockGitUploadPackService) Fetch(r *common.GitUploadPackRequest) (io.Rea
return f.One().Packfile(), nil
}
-func (p *MockGitUploadPackService) Disconnect() error {
- p.connected = false
+func (c *MockFetchPackSession) Close() error {
return nil
}