2013-07-20 09:46:47 +04:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2013-12-10 10:47:15 +04:00
|
|
|
"os"
|
2013-07-20 09:46:47 +04:00
|
|
|
"testing"
|
2014-04-11 08:48:38 +04:00
|
|
|
|
|
|
|
"github.com/bmizerany/assert"
|
|
|
|
"github.com/github/hub/fixtures"
|
2013-07-20 09:46:47 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestParseCherryPickProjectAndSha(t *testing.T) {
|
2014-04-11 08:48:38 +04:00
|
|
|
testConfigs := fixtures.SetupTestConfigs()
|
|
|
|
defer testConfigs.TearDown()
|
|
|
|
|
2013-07-20 09:46:47 +04:00
|
|
|
ref := "https://github.com/jingweno/gh/commit/a319d88#comments"
|
|
|
|
project, sha := parseCherryPickProjectAndSha(ref)
|
|
|
|
|
|
|
|
assert.Equal(t, "jingweno", project.Owner)
|
|
|
|
assert.Equal(t, "gh", project.Name)
|
2014-04-11 08:48:38 +04:00
|
|
|
assert.Equal(t, "github.com", project.Host)
|
|
|
|
assert.Equal(t, "https", project.Protocol)
|
2013-07-20 09:46:47 +04:00
|
|
|
assert.Equal(t, "a319d88", sha)
|
|
|
|
|
|
|
|
ref = "https://github.com/jingweno/gh/commit/a319d88#comments"
|
|
|
|
project, sha = parseCherryPickProjectAndSha(ref)
|
|
|
|
|
|
|
|
assert.Equal(t, "jingweno", project.Owner)
|
|
|
|
assert.Equal(t, "gh", project.Name)
|
|
|
|
assert.Equal(t, "a319d88", sha)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTransformCherryPickArgs(t *testing.T) {
|
2014-04-11 08:48:38 +04:00
|
|
|
testConfigs := fixtures.SetupTestConfigs()
|
|
|
|
defer testConfigs.TearDown()
|
|
|
|
|
2014-10-16 22:55:08 +04:00
|
|
|
args := NewArgs([]string{})
|
|
|
|
transformCherryPickArgs(args)
|
|
|
|
cmds := args.Commands()
|
|
|
|
assert.Equal(t, 1, len(cmds))
|
|
|
|
|
2014-04-08 08:19:57 +04:00
|
|
|
os.Setenv("HUB_PROTOCOL", "git")
|
2014-10-16 22:55:08 +04:00
|
|
|
defer os.Setenv("HUB_PROTOCOL", "")
|
|
|
|
args = NewArgs([]string{"cherry-pick", "https://github.com/jingweno/gh/commit/a319d88#comments"})
|
2013-07-20 09:46:47 +04:00
|
|
|
transformCherryPickArgs(args)
|
|
|
|
|
2014-10-16 22:55:08 +04:00
|
|
|
cmds = args.Commands()
|
2013-07-20 09:46:47 +04:00
|
|
|
assert.Equal(t, 2, len(cmds))
|
|
|
|
assert.Equal(t, "git remote add -f jingweno git://github.com/jingweno/gh.git", cmds[0].String())
|
|
|
|
assert.Equal(t, "git cherry-pick a319d88", cmds[1].String())
|
|
|
|
}
|