aboutsummaryrefslogtreecommitdiffstats
path: root/internal/url/url_test.go
blob: d168db6dfc9cb943781633e975c476dede2c39ae (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
package url

import (
	"testing"

	. "gopkg.in/check.v1"
)

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

type URLSuite struct{}

var _ = Suite(&URLSuite{})

func (s *URLSuite) TestMatchesScpLike(c *C) {
	examples := []string{
		"git@github.com:james/bond",
		"git@github.com:007/bond",
		"git@github.com:22:james/bond",
		"git@github.com:22:007/bond",
	}

	for _, url := range examples {
		c.Check(MatchesScpLike(url), Equals, true)
	}
}

func (s *URLSuite) TestFindScpLikeComponents(c *C) {
	url := "git@github.com:james/bond"
	user, host, port, path := FindScpLikeComponents(url)

	c.Check(user, Equals, "git")
	c.Check(host, Equals, "github.com")
	c.Check(port, Equals, "")
	c.Check(path, Equals, "james/bond")

	url = "git@github.com:007/bond"
	user, host, port, path = FindScpLikeComponents(url)

	c.Check(user, Equals, "git")
	c.Check(host, Equals, "github.com")
	c.Check(port, Equals, "")
	c.Check(path, Equals, "007/bond")

	url = "git@github.com:22:james/bond"
	user, host, port, path = FindScpLikeComponents(url)

	c.Check(user, Equals, "git")
	c.Check(host, Equals, "github.com")
	c.Check(port, Equals, "22")
	c.Check(path, Equals, "james/bond")

	url = "git@github.com:22:007/bond"
	user, host, port, path = FindScpLikeComponents(url)

	c.Check(user, Equals, "git")
	c.Check(host, Equals, "github.com")
	c.Check(port, Equals, "22")
	c.Check(path, Equals, "007/bond")
}