-
Notifications
You must be signed in to change notification settings - Fork 60
/
vcs_remote_lookup_test.go
113 lines (101 loc) · 4.43 KB
/
vcs_remote_lookup_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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package vcs
import (
"io/ioutil"
"os"
"os/exec"
"runtime"
"strings"
"testing"
)
func TestVCSLookup(t *testing.T) {
// TODO: Expand to make sure it detected the right vcs.
urlList := map[string]struct {
work bool
t Type
}{
"https://github.com/masterminds": {work: false, t: Git},
"https://github.com/Masterminds/VCSTestRepo": {work: true, t: Git},
"https://bitbucket.org/mattfarina/atest": {work: true, t: Git},
"https://launchpad.net/govcstestbzrrepo/trunk": {work: true, t: Bzr},
"https://launchpad.net/~mattfarina/+junk/mygovcstestbzrrepo": {work: true, t: Bzr},
"https://launchpad.net/~mattfarina/+junk/mygovcstestbzrrepo/trunk": {work: true, t: Bzr},
"https://git.launchpad.net/govcstestgitrepo": {work: true, t: Git},
"https://git.launchpad.net/~mattfarina/+git/mygovcstestgitrepo": {work: true, t: Git},
"https://hub.jazz.net/git/user1/pkgname": {work: true, t: Git},
"https://hub.jazz.net/git/user1/pkgname/subpkg/subpkg/subpkg": {work: true, t: Git},
"https://hubs.jazz.net/git/user1/pkgname": {work: false, t: Git},
"https://example.com/foo/bar.git": {work: true, t: Git},
"https://example.com/foo/bar.svn": {work: true, t: Svn},
"https://example.com/foo/bar/baz.bzr": {work: true, t: Bzr},
"https://example.com/foo/bar/baz.hg": {work: true, t: Hg},
"https://gopkg.in/tomb.v1": {work: true, t: Git},
"https://golang.org/x/net": {work: true, t: Git},
"https://git.openstack.org/foo/bar": {work: true, t: Git},
"[email protected]:Masterminds/vcs.git": {work: true, t: Git},
"[email protected]:foo.git": {work: true, t: Git},
"ssh://bitbucket.org/mattfarina/testhgrepo": {work: true, t: Git},
"[email protected]:mattfarina/glide-bitbucket-example.git": {work: true, t: Git},
"git+ssh://example.com/foo/bar": {work: true, t: Git},
"git://example.com/foo/bar": {work: true, t: Git},
"bzr+ssh://example.com/foo/bar": {work: true, t: Bzr},
"svn+ssh://example.com/foo/bar": {work: true, t: Svn},
"[email protected]:foo/bar": {work: true, t: Git},
"[email protected]:foo/bar": {work: true, t: Hg},
"http://hg.code.sf.net/p/masterminds/test": {work: true, t: Hg},
"http://git.code.sf.net/p/masterminds/test": {work: true, t: Git},
"http://svn.code.sf.net/p/masterminds/test": {work: true, t: Svn},
}
for u, c := range urlList {
ty, _, err := detectVcsFromRemote(u)
if err == nil && !c.work {
t.Errorf("Error detecting VCS from URL(%s)", u)
}
if err == ErrCannotDetectVCS && c.work {
t.Errorf("Error detecting VCS from URL(%s)", u)
}
if err != nil && c.work {
t.Errorf("Error detecting VCS from URL(%s): %s", u, err)
}
if err != nil &&
err != ErrCannotDetectVCS &&
!strings.HasSuffix(err.Error(), "Not Found") &&
!strings.HasSuffix(err.Error(), "Access Denied") &&
!c.work {
t.Errorf("Unexpected error returned (%s): %s", u, err)
}
if c.work && ty != c.t {
t.Errorf("Incorrect VCS type returned(%s)", u)
}
}
}
func TestVCSFileLookup(t *testing.T) {
tempDir, err := ioutil.TempDir("", "go-vcs-file-lookup-tests")
if err != nil {
t.Error(err)
}
defer func() {
err = os.RemoveAll(tempDir)
if err != nil {
t.Error(err)
}
}()
_, err = exec.Command("git", "init", tempDir).CombinedOutput()
if err != nil {
t.Error(err)
}
// On Windows it should be file:// followed by /C:\for\bar. That / before
// the drive needs to be included in testing.
var pth string
if runtime.GOOS == "windows" {
pth = "file:///" + tempDir
} else {
pth = "file://" + tempDir
}
ty, _, err := detectVcsFromRemote(pth)
if err != nil {
t.Errorf("Unable to detect file:// path: %s", err)
}
if ty != Git {
t.Errorf("Detected wrong type from file:// path. Found type %v", ty)
}
}