Ensure remote URL parsing tests don't read user SSH config files
This commit is contained in:
parent
344906bf03
commit
183db99535
2 changed files with 22 additions and 5 deletions
|
|
@ -17,9 +17,7 @@ var (
|
|||
func init() {
|
||||
RootCmd.PersistentFlags().StringVarP(¤tRepo, "repo", "R", "", "current GitHub repository")
|
||||
RootCmd.PersistentFlags().StringVarP(¤tBranch, "current-branch", "B", "", "current git branch")
|
||||
}
|
||||
|
||||
func initContext() {
|
||||
ctx := context.InitDefaultContext()
|
||||
ctx.SetBranch(currentBranch)
|
||||
repo := currentRepo
|
||||
|
|
@ -27,6 +25,7 @@ func initContext() {
|
|||
repo = os.Getenv("GH_REPO")
|
||||
}
|
||||
ctx.SetBaseRepo(repo)
|
||||
|
||||
git.InitSSHAliasMap(nil)
|
||||
}
|
||||
|
||||
|
|
@ -36,9 +35,6 @@ var RootCmd = &cobra.Command{
|
|||
Short: "GitHub CLI",
|
||||
Long: `Do things with GitHub from your terminal`,
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
||||
initContext()
|
||||
},
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("root")
|
||||
},
|
||||
|
|
|
|||
|
|
@ -2,15 +2,36 @@ package context
|
|||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/github/gh-cli/git"
|
||||
)
|
||||
|
||||
func Test_repoFromURL(t *testing.T) {
|
||||
git.InitSSHAliasMap(nil)
|
||||
|
||||
r, err := repoFromURL("http://github.com/monalisa/octo-cat.git")
|
||||
eq(t, err, nil)
|
||||
eq(t, r, &GitHubRepository{Owner: "monalisa", Name: "octo-cat"})
|
||||
}
|
||||
|
||||
func Test_repoFromURL_SSH(t *testing.T) {
|
||||
git.InitSSHAliasMap(map[string]string{
|
||||
"gh": "github.com",
|
||||
"github.com": "ssh.github.com",
|
||||
})
|
||||
|
||||
r, err := repoFromURL("git@gh:monalisa/octo-cat")
|
||||
eq(t, err, nil)
|
||||
eq(t, r, &GitHubRepository{Owner: "monalisa", Name: "octo-cat"})
|
||||
|
||||
r, err = repoFromURL("git@github.com:monalisa/octo-cat")
|
||||
eq(t, err, nil)
|
||||
eq(t, r, &GitHubRepository{Owner: "monalisa", Name: "octo-cat"})
|
||||
}
|
||||
|
||||
func Test_parseRemotes(t *testing.T) {
|
||||
git.InitSSHAliasMap(nil)
|
||||
|
||||
remoteList := []string{
|
||||
"mona\tgit@github.com:monalisa/myfork.git (fetch)",
|
||||
"origin\thttps://github.com/monalisa/octo-cat.git (fetch)",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue