зеркало из https://github.com/mislav/hub.git
68 строки
2.1 KiB
Go
68 строки
2.1 KiB
Go
package commands
|
|
|
|
import (
|
|
"github.com/bmizerany/assert"
|
|
"github.com/jingweno/gh/github"
|
|
"os"
|
|
"regexp"
|
|
"testing"
|
|
)
|
|
|
|
func TestParseRepoNameOwner(t *testing.T) {
|
|
owner, repo := parseRepoNameOwner("jingweno")
|
|
assert.Equal(t, "jingweno", owner)
|
|
assert.Equal(t, "", repo)
|
|
|
|
owner, repo = parseRepoNameOwner("jingweno/gh")
|
|
assert.Equal(t, "jingweno", owner)
|
|
assert.Equal(t, "gh", repo)
|
|
}
|
|
|
|
func TestTransformRemoteArgs(t *testing.T) {
|
|
os.Setenv("GH_PROTOCOL", "git")
|
|
github.CreateTestConfigs("jingweno", "123")
|
|
|
|
args := NewArgs([]string{"remote", "add", "jingweno"})
|
|
transformRemoteArgs(args)
|
|
|
|
assert.Equal(t, 3, args.ParamsSize())
|
|
assert.Equal(t, "add", args.FirstParam())
|
|
assert.Equal(t, "jingweno", args.GetParam(1))
|
|
reg := regexp.MustCompile("^git://github.com/jingweno/.+\\.git$")
|
|
assert.T(t, reg.MatchString(args.GetParam(2)))
|
|
|
|
args = NewArgs([]string{"remote", "add", "-p", "jingweno"})
|
|
transformRemoteArgs(args)
|
|
|
|
assert.Equal(t, 3, args.ParamsSize())
|
|
assert.Equal(t, "add", args.FirstParam())
|
|
assert.Equal(t, "jingweno", args.GetParam(1))
|
|
reg = regexp.MustCompile("^git@github.com:jingweno/.+\\.git$")
|
|
assert.T(t, reg.MatchString(args.GetParam(2)))
|
|
|
|
args = NewArgs([]string{"remote", "add", "origin"})
|
|
transformRemoteArgs(args)
|
|
|
|
assert.Equal(t, 3, args.ParamsSize())
|
|
assert.Equal(t, "add", args.FirstParam())
|
|
assert.Equal(t, "origin", args.GetParam(1))
|
|
reg = regexp.MustCompile("^git://github.com/.+/.+\\.git$")
|
|
assert.T(t, reg.MatchString(args.GetParam(2)))
|
|
|
|
args = NewArgs([]string{"remote", "add", "jingweno", "git@github.com:jingweno/gh.git"})
|
|
transformRemoteArgs(args)
|
|
|
|
assert.Equal(t, 3, args.ParamsSize())
|
|
assert.Equal(t, "jingweno", args.GetParam(1))
|
|
assert.Equal(t, "add", args.FirstParam())
|
|
assert.Equal(t, "git@github.com:jingweno/gh.git", args.GetParam(2))
|
|
|
|
args = NewArgs([]string{"remote", "add", "-p", "origin", "org/foo"})
|
|
transformRemoteArgs(args)
|
|
|
|
assert.Equal(t, 3, args.ParamsSize())
|
|
assert.Equal(t, "origin", args.GetParam(1))
|
|
assert.Equal(t, "add", args.FirstParam())
|
|
assert.Equal(t, "git@github.com:org/foo.git", args.GetParam(2))
|
|
}
|