@@ -2,67 +2,43 @@ package context
22
33import (
44 "errors"
5+ "net/url"
56 "testing"
67
78 "github.com/github/gh-cli/git"
89)
910
1011func Test_repoFromURL (t * testing.T ) {
11- git .InitSSHAliasMap (nil )
12-
13- r , err := repoFromURL ("http://github.com/monalisa/octo-cat.git" )
12+ u , _ := url .Parse ("http://github.com/monalisa/octo-cat.git" )
13+ owner , repo , err := repoFromURL (u )
1414 eq (t , err , nil )
15- eq (t , r , & GitHubRepository {Owner : "monalisa" , Name : "octo-cat" })
15+ eq (t , owner , "monalisa" )
16+ eq (t , repo , "octo-cat" )
1617}
1718
1819func Test_repoFromURL_invalid (t * testing.T ) {
19- git .InitSSHAliasMap (nil )
20-
21- _ , err := repoFromURL ("https://example.com/one/two" )
22- eq (t , err , errors .New (`invalid hostname: example.com` ))
23-
24- _ , err = repoFromURL ("/path/to/disk" )
25- eq (t , err , errors .New (`invalid hostname: ` ))
26- }
27-
28- func Test_repoFromURL_SSH (t * testing.T ) {
29- git .InitSSHAliasMap (map [string ]string {
30- "gh" : "github.com" ,
31- "github.com" : "ssh.github.com" ,
32- })
33-
34- r , err := repoFromURL ("git@gh:monalisa/octo-cat" )
35- eq (t , err , nil )
36- eq (t , r , & GitHubRepository {Owner : "monalisa" , Name : "octo-cat" })
37-
38- r , err = repoFromURL ("git@github.com:monalisa/octo-cat" )
39- eq (t , err , nil )
40- eq (t , r , & GitHubRepository {Owner : "monalisa" , Name : "octo-cat" })
41- }
42-
43- func Test_parseRemotes (t * testing.T ) {
44- git .InitSSHAliasMap (nil )
45-
46- remoteList := []string {
47- "mona\t git@github.com:monalisa/myfork.git (fetch)" ,
48- "origin\t https://github.com/monalisa/octo-cat.git (fetch)" ,
49- "origin\t https://github.com/monalisa/octo-cat-push.git (push)" ,
50- "upstream\t https://example.com/nowhere.git (fetch)" ,
51- "upstream\t https://github.com/hubot/tools (push)" ,
20+ cases := [][]string {
21+ []string {
22+ "https://example.com/one/two" ,
23+ "unsupported hostname: example.com" ,
24+ },
25+ []string {
26+ "/path/to/disk" ,
27+ "unsupported hostname: " ,
28+ },
29+ }
30+ for _ , c := range cases {
31+ u , _ := url .Parse (c [0 ])
32+ _ , _ , err := repoFromURL (u )
33+ eq (t , err , errors .New (c [1 ]))
5234 }
53- r := parseRemotes (remoteList )
54- eq (t , len (r ), 3 )
55-
56- eq (t , r [0 ], & Remote {Name : "mona" , Owner : "monalisa" , Repo : "myfork" })
57- eq (t , r [1 ], & Remote {Name : "origin" , Owner : "monalisa" , Repo : "octo-cat" })
58- eq (t , r [2 ], & Remote {Name : "upstream" , Owner : "hubot" , Repo : "tools" })
5935}
6036
6137func Test_Remotes_FindByName (t * testing.T ) {
6238 list := Remotes {
63- & Remote {Name : "mona" , Owner : "monalisa" , Repo : "myfork" },
64- & Remote {Name : "origin" , Owner : "monalisa" , Repo : "octo-cat" },
65- & Remote {Name : "upstream" , Owner : "hubot" , Repo : "tools" },
39+ & Remote {Remote : & git. Remote { Name : "mona" } , Owner : "monalisa" , Repo : "myfork" },
40+ & Remote {Remote : & git. Remote { Name : "origin" } , Owner : "monalisa" , Repo : "octo-cat" },
41+ & Remote {Remote : & git. Remote { Name : "upstream" } , Owner : "hubot" , Repo : "tools" },
6642 }
6743
6844 r , err := list .FindByName ("upstream" , "origin" )
0 commit comments