aboutsummaryrefslogtreecommitdiffstats
path: root/clients/common_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'clients/common_test.go')
-rw-r--r--clients/common_test.go93
1 files changed, 33 insertions, 60 deletions
diff --git a/clients/common_test.go b/clients/common_test.go
index f27b814..72d8e99 100644
--- a/clients/common_test.go
+++ b/clients/common_test.go
@@ -3,69 +3,68 @@ package clients
import (
"fmt"
"io"
- "os"
"testing"
"gopkg.in/src-d/go-git.v4/clients/common"
- "github.com/alcortesm/tgz"
. "gopkg.in/check.v1"
)
func Test(t *testing.T) { TestingT(t) }
-type SuiteCommon struct {
- dirFixturePath string
-}
+type SuiteCommon struct{}
var _ = Suite(&SuiteCommon{})
-const fixtureTGZ = "../storage/filesystem/internal/dotgit/fixtures/spinnaker-gc.tgz"
+func (s *SuiteCommon) TestNewGitUploadPackServiceHTTP(c *C) {
+ e, err := common.NewEndpoint("http://github.com/src-d/go-git")
+ c.Assert(err, IsNil)
+
+ output, err := NewGitUploadPackService(e)
+ c.Assert(err, IsNil)
+ c.Assert(typeAsString(output), Equals, "*http.GitUploadPackService")
+
+ e, err = common.NewEndpoint("https://github.com/src-d/go-git")
+ c.Assert(err, IsNil)
+
+ output, err = NewGitUploadPackService(e)
+ c.Assert(err, IsNil)
+ c.Assert(typeAsString(output), Equals, "*http.GitUploadPackService")
+}
+
+func (s *SuiteCommon) TestNewGitUploadPackServiceSSH(c *C) {
+ e, err := common.NewEndpoint("ssh://github.com/src-d/go-git")
+ c.Assert(err, IsNil)
-func (s *SuiteCommon) SetUpSuite(c *C) {
- var err error
- s.dirFixturePath, err = tgz.Extract(fixtureTGZ)
+ output, err := NewGitUploadPackService(e)
c.Assert(err, IsNil)
+ c.Assert(typeAsString(output), Equals, "*ssh.GitUploadPackService")
}
-func (s *SuiteCommon) TearDownSuite(c *C) {
- err := os.RemoveAll(s.dirFixturePath)
+func (s *SuiteCommon) TestNewGitUploadPackServiceUnknown(c *C) {
+ e, err := common.NewEndpoint("unknown://github.com/src-d/go-git")
c.Assert(err, IsNil)
+
+ _, err = NewGitUploadPackService(e)
+ c.Assert(err, NotNil)
}
-func (s *SuiteCommon) TestNewGitUploadPackService(c *C) {
- var tests = [...]struct {
- input string
- err bool
- exp string
- }{
- {"://example.com", true, "<nil>"},
- {"badscheme://github.com/src-d/go-git", true, "<nil>"},
- {"http://github.com/src-d/go-git", false, "*http.GitUploadPackService"},
- {"https://github.com/src-d/go-git", false, "*http.GitUploadPackService"},
- {"ssh://github.com/src-d/go-git", false, "*ssh.GitUploadPackService"},
- }
-
- for i, t := range tests {
- output, err := NewGitUploadPackService(t.input)
- c.Assert(err != nil, Equals, t.err,
- Commentf("%d) %q: wrong error value (was: %s)", i, t.input, err))
- c.Assert(typeAsString(output), Equals, t.exp,
- Commentf("%d) %q: wrong type", i, t.input))
- }
+func (s *SuiteCommon) TestInstallProtocol(c *C) {
+ InstallProtocol("newscheme", newDummyProtocolService)
+ c.Assert(Protocols["newscheme"], NotNil)
}
type dummyProtocolService struct{}
-func newDummyProtocolService() common.GitUploadPackService {
+func newDummyProtocolService(common.Endpoint) common.GitUploadPackService {
return &dummyProtocolService{}
}
-func (s *dummyProtocolService) Connect(url common.Endpoint) error {
+func (s *dummyProtocolService) Connect() error {
return nil
}
-func (s *dummyProtocolService) ConnectWithAuth(url common.Endpoint, auth common.AuthMethod) error {
+func (s *dummyProtocolService) ConnectWithAuth(auth common.AuthMethod) error {
return nil
}
@@ -77,32 +76,6 @@ func (s *dummyProtocolService) Fetch(r *common.GitUploadPackRequest) (io.ReadClo
return nil, nil
}
-func (s *SuiteCommon) TestInstallProtocol(c *C) {
- var tests = [...]struct {
- scheme string
- service common.GitUploadPackService
- panic bool
- }{
- {"panic", nil, true},
- {"newscheme", newDummyProtocolService(), false},
- {"http", newDummyProtocolService(), false},
- }
-
- for i, t := range tests {
- if t.panic {
- c.Assert(func() { InstallProtocol(t.scheme, t.service) }, PanicMatches, `nil service`)
- continue
- }
-
- 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)
- }
- }
-}
-
func typeAsString(v interface{}) string {
return fmt.Sprintf("%T", v)
}