forked from cli/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremote_test.go
More file actions
54 lines (46 loc) · 1.2 KB
/
remote_test.go
File metadata and controls
54 lines (46 loc) · 1.2 KB
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
package context
import (
"errors"
"net/url"
"testing"
"github.com/github/gh-cli/git"
)
func Test_repoFromURL(t *testing.T) {
u, _ := url.Parse("http://github.com/monalisa/octo-cat.git")
owner, repo, err := repoFromURL(u)
eq(t, err, nil)
eq(t, owner, "monalisa")
eq(t, repo, "octo-cat")
}
func Test_repoFromURL_invalid(t *testing.T) {
cases := [][]string{
[]string{
"https://example.com/one/two",
"unsupported hostname: example.com",
},
[]string{
"/path/to/disk",
"unsupported hostname: ",
},
}
for _, c := range cases {
u, _ := url.Parse(c[0])
_, _, err := repoFromURL(u)
eq(t, err, errors.New(c[1]))
}
}
func Test_Remotes_FindByName(t *testing.T) {
list := Remotes{
&Remote{Remote: &git.Remote{Name: "mona"}, Owner: "monalisa", Repo: "myfork"},
&Remote{Remote: &git.Remote{Name: "origin"}, Owner: "monalisa", Repo: "octo-cat"},
&Remote{Remote: &git.Remote{Name: "upstream"}, Owner: "hubot", Repo: "tools"},
}
r, err := list.FindByName("upstream", "origin")
eq(t, err, nil)
eq(t, r.Name, "upstream")
r, err = list.FindByName("nonexist", "*")
eq(t, err, nil)
eq(t, r.Name, "mona")
_, err = list.FindByName("nonexist")
eq(t, err, errors.New(`no GitHub remotes found`))
}