forked from x-motemen/ghq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
remote_repository_test.go
60 lines (57 loc) · 1.44 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
package main
import (
"testing"
)
func TestNewRemoteRepository(t *testing.T) {
testCases := []struct {
url string
valid bool
vcsBackend *VCSBackend
repoURL string
}{{
url: "https://github.com/motemen/pusheen-explorer",
valid: true,
vcsBackend: GitBackend,
}, {
url: "https://github.com/motemen/pusheen-explorer/",
valid: true,
vcsBackend: GitBackend,
}, {
url: "https://github.com/motemen/ghq/logger",
valid: true,
vcsBackend: GitBackend,
repoURL: "https://github.com/motemen/ghq",
}, {
url: "https://example.com/motemen/pusheen-explorer/",
valid: true,
vcsBackend: nil,
}, {
url: "https://gist.github.com/motemen/9733745",
valid: true,
vcsBackend: GitBackend,
}, {
url: "http://hub.darcs.net/foo/bar",
valid: true,
vcsBackend: DarcsBackend,
}}
for _, tc := range testCases {
t.Run(tc.url, func(t *testing.T) {
repo, err := NewRemoteRepository(mustParseURL(tc.url))
if err != nil {
t.Errorf("error should be nil but: %s", err)
}
if repo.IsValid() != tc.valid {
t.Errorf("repo.IsValid() should be %v, but %v", tc.valid, repo.IsValid())
}
vcs, u := repo.VCS()
if vcs != tc.vcsBackend {
t.Errorf("got: %+v, expect: %+v", vcs, tc.vcsBackend)
}
if tc.repoURL != "" {
if u.String() != tc.repoURL {
t.Errorf("repoURL: got: %s, expect: %s", u.String(), tc.repoURL)
}
}
})
}
}