-
-
Notifications
You must be signed in to change notification settings - Fork 184
/
remote_repository_test.go
123 lines (116 loc) · 2.91 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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,
}, {
url: "http://nest.pijul.com/foo/bar",
valid: true,
vcsBackend: PijulBackend,
}, {
url: "svn+ssh://example.com/proj/repo",
valid: true,
vcsBackend: SubversionBackend,
}}
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)
}
}
})
}
}
func TestNewRemoteRepository_vcs_error(t *testing.T) {
testCases := []struct {
url string
valid bool
vcsBackend *VCSBackend
repoURL string
}{{
url: "https://example.com/motemen/pusheen-explorer/",
valid: true,
vcsBackend: nil,
}}
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, err := repo.VCS()
if err == nil {
t.Fatalf("error should be nil but: %s", err)
}
if vcs != tc.vcsBackend {
t.Errorf("got: %+v, expect: %+v", vcs, tc.vcsBackend)
}
if u != nil {
t.Errorf("u should be nil: %s", u.String())
}
})
}
}
func TestNewRemoteRepository_error(t *testing.T) {
testCases := []struct {
url string
}{{
url: "https://github.com/blog/github",
}}
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 != nil {
t.Errorf("repo should be nil: %v", repo)
}
})
}
}