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.go62
1 files changed, 56 insertions, 6 deletions
diff --git a/clients/common_test.go b/clients/common_test.go
index f8bcbd3..ff9ca32 100644
--- a/clients/common_test.go
+++ b/clients/common_test.go
@@ -2,9 +2,11 @@ package clients
import (
"fmt"
+ "io"
"testing"
. "gopkg.in/check.v1"
+ "gopkg.in/src-d/go-git.v2/clients/common"
)
func Test(t *testing.T) { TestingT(t) }
@@ -19,20 +21,68 @@ func (s *SuiteCommon) TestNewGitUploadPackService(c *C) {
err bool
expected string
}{
- {"ht/ml://example.com", true, "<nil>"},
- {"", true, "<nil>"},
- {"-", true, "<nil>"},
- {"!@", true, "<nil>"},
+ {"://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"},
- {"file://github.com/src-d/go-git", false, "*file.GitUploadPackService"},
}
for i, t := range tests {
output, err := NewGitUploadPackService(t.input)
c.Assert(err != nil, Equals, t.err, Commentf("%d) %q: wrong error value", i, t.input))
- c.Assert(fmt.Sprintf("%T", output), Equals, t.expected, Commentf("%d) %q: wrong type", i, t.input))
+ c.Assert(typeAsString(output), Equals, t.expected, Commentf("%d) %q: wrong type", i, t.input))
}
}
+
+type dummyProtocolService struct{}
+
+func newDummyProtocolService(url string) common.GitUploadPackService {
+ return &dummyProtocolService{}
+}
+
+func (s *dummyProtocolService) Connect(url common.Endpoint) error {
+ return nil
+}
+
+func (s *dummyProtocolService) ConnectWithAuth(url common.Endpoint, auth common.AuthMethod) error {
+ return nil
+}
+
+func (s *dummyProtocolService) Info() (*common.GitUploadPackInfo, error) {
+ return nil, nil
+}
+
+func (s *dummyProtocolService) Fetch(r *common.GitUploadPackRequest) (io.ReadCloser, error) {
+ return nil, nil
+}
+
+func (s *SuiteCommon) TestInstallProtocol(c *C) {
+ var tests = [...]struct {
+ scheme string
+ serviceFn ServiceFromURLFunc
+ panic bool
+ }{
+ {"panic", nil, true},
+ {"newscheme", newDummyProtocolService, false},
+ {"http", newDummyProtocolService, false},
+ }
+
+ for i, t := range tests {
+ if t.panic {
+ fmt.Println(t.serviceFn == nil)
+ c.Assert(func() { InstallProtocol(t.scheme, t.serviceFn) }, PanicMatches, `nil service`)
+ continue
+ }
+ InstallProtocol(t.scheme, t.serviceFn)
+ c.Assert(typeAsString(KnownProtocols[t.scheme]), Equals, typeAsString(t.serviceFn), 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)
+}