github.com/kazu/ghq@v0.8.1-0.20180818162325-dedd532b4440/remote_repository_test.go (about) 1 package main 2 3 import ( 4 "errors" 5 "net/url" 6 7 "github.com/motemen/ghq/utils" 8 . "github.com/onsi/gomega" 9 ) 10 import "testing" 11 12 func parseURL(urlString string) *url.URL { 13 u, err := url.Parse(urlString) 14 if err != nil { 15 panic(err) 16 } 17 return u 18 } 19 20 func TestNewRemoteRepositoryGitHub(t *testing.T) { 21 RegisterTestingT(t) 22 23 var ( 24 repo RemoteRepository 25 err error 26 ) 27 28 repo, err = NewRemoteRepository(parseURL("https://github.com/motemen/pusheen-explorer")) 29 Expect(err).To(BeNil()) 30 Expect(repo.IsValid()).To(Equal(true)) 31 Expect(repo.VCS()).To(Equal(GitBackend)) 32 33 repo, err = NewRemoteRepository(parseURL("https://github.com/motemen/pusheen-explorer/")) 34 Expect(err).To(BeNil()) 35 Expect(repo.IsValid()).To(Equal(true)) 36 Expect(repo.VCS()).To(Equal(GitBackend)) 37 38 repo, err = NewRemoteRepository(parseURL("https://github.com/motemen/pusheen-explorer/blob/master/README.md")) 39 Expect(err).To(BeNil()) 40 Expect(repo.IsValid()).To(Equal(false)) 41 42 repo, err = NewRemoteRepository(parseURL("https://example.com/motemen/pusheen-explorer")) 43 Expect(err).To(BeNil()) 44 Expect(repo.IsValid()).To(Equal(true)) 45 } 46 47 func TestNewRemoteRepositoryGitHubGist(t *testing.T) { 48 RegisterTestingT(t) 49 50 var ( 51 repo RemoteRepository 52 err error 53 ) 54 55 repo, err = NewRemoteRepository(parseURL("https://gist.github.com/motemen/9733745")) 56 Expect(err).To(BeNil()) 57 Expect(repo.IsValid()).To(Equal(true)) 58 Expect(repo.VCS()).To(Equal(GitBackend)) 59 } 60 61 func TestNewRemoteRepositoryGoogleCode(t *testing.T) { 62 RegisterTestingT(t) 63 64 var ( 65 repo RemoteRepository 66 err error 67 ) 68 69 repo, err = NewRemoteRepository(parseURL("https://code.google.com/p/vim/")) 70 Expect(err).To(BeNil()) 71 Expect(repo.IsValid()).To(Equal(true)) 72 utils.CommandRunner = NewFakeRunner(map[string]error{ 73 "hg identify": nil, 74 "git ls-remote": errors.New(""), 75 }) 76 Expect(repo.VCS()).To(Equal(MercurialBackend)) 77 78 repo, err = NewRemoteRepository(parseURL("https://code.google.com/p/git-core")) 79 Expect(err).To(BeNil()) 80 Expect(repo.IsValid()).To(Equal(true)) 81 utils.CommandRunner = NewFakeRunner(map[string]error{ 82 "hg identify": errors.New(""), 83 "git ls-remote": nil, 84 }) 85 Expect(repo.VCS()).To(Equal(GitBackend)) 86 } 87 88 func TestNewRemoteRepositoryDarcsHub(t *testing.T) { 89 RegisterTestingT(t) 90 91 repo, err := NewRemoteRepository(parseURL("http://hub.darcs.net/foo/bar")) 92 Expect(err).To(BeNil()) 93 Expect(repo.IsValid()).To(Equal(true)) 94 Expect(repo.VCS()).To(Equal(DarcsBackend)) 95 }