aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/transport/common_test.go
blob: ce410450875d6429f7145279addca6f1c0da379e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package transport

import (
	"testing"

	"gopkg.in/src-d/go-git.v4/plumbing/protocol/packp/capability"

	. "gopkg.in/check.v1"
)

func Test(t *testing.T) { TestingT(t) }

type SuiteCommon struct{}

var _ = Suite(&SuiteCommon{})

func (s *SuiteCommon) TestNewEndpointHTTP(c *C) {
	e, err := NewEndpoint("http://git:pass@github.com/user/repository.git?foo#bar")
	c.Assert(err, IsNil)
	c.Assert(e.Protocol(), Equals, "http")
	c.Assert(e.User(), Equals, "git")
	c.Assert(e.Password(), Equals, "pass")
	c.Assert(e.Host(), Equals, "github.com")
	c.Assert(e.Port(), Equals, 0)
	c.Assert(e.Path(), Equals, "/user/repository.git?foo#bar")
	c.Assert(e.String(), Equals, "http://git:pass@github.com/user/repository.git?foo#bar")
}

func (s *SuiteCommon) TestNewEndpointSSH(c *C) {
	e, err := NewEndpoint("ssh://git@github.com/user/repository.git")
	c.Assert(err, IsNil)
	c.Assert(e.Protocol(), Equals, "ssh")
	c.Assert(e.User(), Equals, "git")
	c.Assert(e.Password(), Equals, "")
	c.Assert(e.Host(), Equals, "github.com")
	c.Assert(e.Port(), Equals, 0)
	c.Assert(e.Path(), Equals, "/user/repository.git")
	c.Assert(e.String(), Equals, "ssh://git@github.com/user/repository.git")
}

func (s *SuiteCommon) TestNewEndpointSSHNoUser(c *C) {
	e, err := NewEndpoint("ssh://github.com/user/repository.git")
	c.Assert(err, IsNil)
	c.Assert(e.Protocol(), Equals, "ssh")
	c.Assert(e.User(), Equals, "")
	c.Assert(e.Password(), Equals, "")
	c.Assert(e.Host(), Equals, "github.com")
	c.Assert(e.Port(), Equals, 0)
	c.Assert(e.Path(), Equals, "/user/repository.git")
	c.Assert(e.String(), Equals, "ssh://github.com/user/repository.git")
}

func (s *SuiteCommon) TestNewEndpointSSHWithPort(c *C) {
	e, err := NewEndpoint("ssh://git@github.com:777/user/repository.git")
	c.Assert(err, IsNil)
	c.Assert(e.Protocol(), Equals, "ssh")
	c.Assert(e.User(), Equals, "git")
	c.Assert(e.Password(), Equals, "")
	c.Assert(e.Host(), Equals, "github.com")
	c.Assert(e.Port(), Equals, 777)
	c.Assert(e.Path(), Equals, "/user/repository.git")
	c.Assert(e.String(), Equals, "ssh://git@github.com:777/user/repository.git")
}

func (s *SuiteCommon) TestNewEndpointSCPLike(c *C) {
	e, err := NewEndpoint("git@github.com:user/repository.git")
	c.Assert(err, IsNil)
	c.Assert(e.Protocol(), Equals, "ssh")
	c.Assert(e.User(), Equals, "git")
	c.Assert(e.Password(), Equals, "")
	c.Assert(e.Host(), Equals, "github.com")
	c.Assert(e.Port(), Equals, 22)
	c.Assert(e.Path(), Equals, "user/repository.git")
	c.Assert(e.String(), Equals, "git@github.com:user/repository.git")
}

func (s *SuiteCommon) TestNewEndpointWrongForgat(c *C) {
	e, err := NewEndpoint("foo")
	c.Assert(err, NotNil)
	c.Assert(e, IsNil)
}

func (s *SuiteCommon) TestFilterUnsupportedCapabilities(c *C) {
	l := capability.NewList()
	l.Set(capability.MultiACK)

	FilterUnsupportedCapabilities(l)
	c.Assert(l.Supports(capability.MultiACK), Equals, false)
}