-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgosrcdir_test.go
82 lines (72 loc) · 2.13 KB
/
gosrcdir_test.go
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
package main
import (
"reflect"
"testing"
)
type ParseTest struct {
Name string
Repo string
}
func TestParsesStandardURL(t *testing.T) {
for _, test := range []ParseTest{
{"HTTPS", "https://[email protected]/path/to/repo"},
{"SSH", "ssh://[email protected]/path/to/repo"},
{"Empty path elements", "https://[email protected]//path//to//repo"},
} {
repoPath, err := parseStandardURL(test.Repo)
if err != nil {
t.Errorf("%s: Unexpected error %q", test.Name, err)
}
expectedPath := []string{"host.com", "path", "to", "repo"}
if !reflect.DeepEqual(repoPath, expectedPath) {
t.Errorf("%s: Expected %q, got %q", test.Name, expectedPath, repoPath)
}
}
}
func TestParsesWeirdGitURL(t *testing.T) {
for _, test := range []ParseTest{
{"with user", "[email protected]:path/to/repo"},
{"without user", "host.com:path/to/repo"},
} {
repoPath, err := parseWeirdGitURL(test.Repo)
if err != nil {
t.Errorf("%s: Unexpected error %q", test.Name, err)
}
expectedPath := []string{"host.com", "path", "to", "repo"}
if !reflect.DeepEqual(repoPath, expectedPath) {
t.Errorf("%s: Expected %q, got %q", test.Name, expectedPath, repoPath)
}
}
}
func TestIsIntolerantToEmptyPathElementsInWeirdURL(t *testing.T) {
_, err := parseWeirdGitURL("[email protected]:path/to//repo")
if err == nil {
t.Errorf("Expected error, got %q", err)
}
}
func TestSourcePath(t *testing.T) {
for _, test := range []ParseTest{
{"Standard URL", "https://[email protected]/path/to/repo"},
{"Weird URL", "[email protected]:path/to/repo"},
} {
repoPath, err := calculateSourcePath("/home/user", test.Repo)
if err != nil {
t.Errorf("%s: Unexpected error %q", test.Name, err)
}
expectedPath := "/home/user/src/host.com/path/to"
if repoPath != expectedPath {
t.Errorf("%sExpected %q, got %q", test.Name, expectedPath, repoPath)
}
}
}
func TestSourcePathErrorsIfMissingHostOrPath(t *testing.T) {
for _, test := range []ParseTest{
{"Standard URL", "https://[email protected]/"},
{"Weird URL", "[email protected]:"},
} {
_, err := calculateSourcePath("/home/user", "[email protected]:")
if err == nil {
t.Errorf("%s: Expected error, got %q", test.Name, err)
}
}
}