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
|
package url
import (
"testing"
)
func TestMatchesScpLike(t *testing.T) {
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 {
if !MatchesScpLike(url) {
t.Fatalf("repo url %q did not match ScpLike", url)
}
}
}
func TestFindScpLikeComponents(t *testing.T) {
url := "git@github.com:james/bond"
user, host, port, path := FindScpLikeComponents(url)
if user != "git" || host != "github.com" || port != "" || path != "james/bond" {
t.Fatalf("repo url %q did not match properly", user)
}
url = "git@github.com:007/bond"
user, host, port, path = FindScpLikeComponents(url)
if user != "git" || host != "github.com" || port != "" || path != "007/bond" {
t.Fatalf("repo url %q did not match properly", user)
}
url = "git@github.com:22:james/bond"
user, host, port, path = FindScpLikeComponents(url)
if user != "git" || host != "github.com" || port != "22" || path != "james/bond" {
t.Fatalf("repo url %q did not match properly", user)
}
url = "git@github.com:22:007/bond"
user, host, port, path = FindScpLikeComponents(url)
if user != "git" || host != "github.com" || port != "22" || path != "007/bond" {
t.Fatalf("repo url %q did not match properly", user)
}
}
|