Exemplo n.º 1
0
func TestTransformSubmoduleArgs(t *testing.T) {
	github.DefaultConfigFile = "./test_support/submodule_gh"
	config := github.Config{User: "******", Token: "123"}
	github.SaveConfig(&config)
	defer os.RemoveAll(filepath.Dir(github.DefaultConfigFile))

	args := NewArgs([]string{"submodule", "add", "jingweno/gh", "vendor/gh"})
	transformSubmoduleArgs(args)

	cmds := args.Commands()
	assert.Equal(t, 1, len(cmds))
	assert.Equal(t, "git submodule add git://github.com/jingweno/gh.git vendor/gh", cmds[0].String())

	args = NewArgs([]string{"submodule", "add", "-p", "jingweno/gh",
		"vendor/gh"})
	transformSubmoduleArgs(args)

	cmds = args.Commands()
	assert.Equal(t, 1, len(cmds))
	assert.Equal(t, "git submodule add [email protected]:jingweno/gh.git vendor/gh", cmds[0].String())

	args = NewArgs([]string{"submodule", "add", "-b", "gh", "--name", "gh", "jingweno/gh", "vendor/gh"})
	transformSubmoduleArgs(args)

	cmds = args.Commands()
	assert.Equal(t, 1, len(cmds))
	assert.Equal(t, "git submodule add -b gh --name gh git://github.com/jingweno/gh.git vendor/gh", cmds[0].String())
}
Exemplo n.º 2
0
func TestTransformRemoteArgs(t *testing.T) {
	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("^[email protected]:jingweno/.+\\.git$")
	assert.T(t, reg.MatchString(args.GetParam(2)))

	github.DefaultConfigFile = "./test_support/gh"
	config := github.Config{User: "******", Token: "123"}
	github.SaveConfig(&config)
	defer os.RemoveAll(filepath.Dir(github.DefaultConfigFile))

	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", "[email protected]: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, "[email protected]: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, "[email protected]:org/foo.git", args.GetParam(2))
}
Exemplo n.º 3
0
func TestTransformCloneArgs(t *testing.T) {
	github.DefaultConfigFile = "./test_support/clone_gh"
	config := github.Config{User: "******", Token: "123"}
	github.SaveConfig(&config)
	defer os.RemoveAll(filepath.Dir(github.DefaultConfigFile))

	args := NewArgs([]string{"clone", "foo/gh"})
	transformCloneArgs(args)

	assert.Equal(t, 1, args.ParamsSize())
	assert.Equal(t, "git://github.com/foo/gh.git", args.FirstParam())

	args = NewArgs([]string{"clone", "-p", "foo/gh"})
	transformCloneArgs(args)

	assert.Equal(t, 1, args.ParamsSize())
	assert.Equal(t, "[email protected]:foo/gh.git", args.FirstParam())

	args = NewArgs([]string{"clone", "jingweno/gh"})
	transformCloneArgs(args)

	assert.Equal(t, 1, args.ParamsSize())
	assert.Equal(t, "[email protected]:jingweno/gh.git", args.FirstParam())

	args = NewArgs([]string{"clone", "-p", "acl-services/devise-acl"})
	transformCloneArgs(args)

	assert.Equal(t, 1, args.ParamsSize())
	assert.Equal(t, "[email protected]:acl-services/devise-acl.git", args.FirstParam())

	args = NewArgs([]string{"clone", "jekyll_and_hyde"})
	transformCloneArgs(args)

	assert.Equal(t, 1, args.ParamsSize())
	assert.Equal(t, "[email protected]:jingweno/jekyll_and_hyde.git", args.FirstParam())

	args = NewArgs([]string{"clone", "-p", "jekyll_and_hyde"})
	transformCloneArgs(args)

	assert.Equal(t, 1, args.ParamsSize())
	assert.Equal(t, "[email protected]:jingweno/jekyll_and_hyde.git", args.FirstParam())

	args = NewArgs([]string{"clone", "git://github.com/jingweno/gh", "gh"})
	transformCloneArgs(args)

	assert.Equal(t, 2, args.ParamsSize())
	assert.Equal(t, "git://github.com/jingweno/gh", args.FirstParam())
	assert.Equal(t, "gh", args.GetParam(1))
}