forked from x-motemen/ghq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
remote_repository_test.go
95 lines (77 loc) · 2.37 KB
/
remote_repository_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
package main
import (
"errors"
"net/url"
"github.com/motemen/ghq/utils"
. "github.com/onsi/gomega"
)
import "testing"
func parseURL(urlString string) *url.URL {
u, err := url.Parse(urlString)
if err != nil {
panic(err)
}
return u
}
func TestNewRemoteRepositoryGitHub(t *testing.T) {
RegisterTestingT(t)
var (
repo RemoteRepository
err error
)
repo, err = NewRemoteRepository(parseURL("https://github.com/motemen/pusheen-explorer"))
Expect(err).To(BeNil())
Expect(repo.IsValid()).To(Equal(true))
Expect(repo.VCS()).To(Equal(GitBackend))
repo, err = NewRemoteRepository(parseURL("https://github.com/motemen/pusheen-explorer/"))
Expect(err).To(BeNil())
Expect(repo.IsValid()).To(Equal(true))
Expect(repo.VCS()).To(Equal(GitBackend))
repo, err = NewRemoteRepository(parseURL("https://github.com/motemen/pusheen-explorer/blob/master/README.md"))
Expect(err).To(BeNil())
Expect(repo.IsValid()).To(Equal(false))
repo, err = NewRemoteRepository(parseURL("https://example.com/motemen/pusheen-explorer"))
Expect(err).To(BeNil())
Expect(repo.IsValid()).To(Equal(true))
}
func TestNewRemoteRepositoryGitHubGist(t *testing.T) {
RegisterTestingT(t)
var (
repo RemoteRepository
err error
)
repo, err = NewRemoteRepository(parseURL("https://gist.github.com/motemen/9733745"))
Expect(err).To(BeNil())
Expect(repo.IsValid()).To(Equal(true))
Expect(repo.VCS()).To(Equal(GitBackend))
}
func TestNewRemoteRepositoryGoogleCode(t *testing.T) {
RegisterTestingT(t)
var (
repo RemoteRepository
err error
)
repo, err = NewRemoteRepository(parseURL("https://code.google.com/p/vim/"))
Expect(err).To(BeNil())
Expect(repo.IsValid()).To(Equal(true))
utils.CommandRunner = NewFakeRunner(map[string]error{
"hg identify": nil,
"git ls-remote": errors.New(""),
})
Expect(repo.VCS()).To(Equal(MercurialBackend))
repo, err = NewRemoteRepository(parseURL("https://code.google.com/p/git-core"))
Expect(err).To(BeNil())
Expect(repo.IsValid()).To(Equal(true))
utils.CommandRunner = NewFakeRunner(map[string]error{
"hg identify": errors.New(""),
"git ls-remote": nil,
})
Expect(repo.VCS()).To(Equal(GitBackend))
}
func TestNewRemoteRepositoryDarcsHub(t *testing.T) {
RegisterTestingT(t)
repo, err := NewRemoteRepository(parseURL("http://hub.darcs.net/foo/bar"))
Expect(err).To(BeNil())
Expect(repo.IsValid()).To(Equal(true))
Expect(repo.VCS()).To(Equal(DarcsBackend))
}