예제 #1
0
파일: url_test.go 프로젝트: ZBNA/deploy
func TestParseURL(t *testing.T) {
	testConfigs := fixtures.SetupTestConfigs()
	defer testConfigs.TearDown()

	url, err :=
		ParseURL("https://github.com/jingweno/gh/pulls/21")
	assert.Equal(t, nil, err)
	assert.Equal(t, "jingweno", url.Owner)
	assert.Equal(t, "gh", url.Name)
	assert.Equal(t, "pulls/21", url.ProjectPath())

	url, err =
		ParseURL("https://github.com/jingweno/gh")
	assert.Equal(t, nil, err)
	assert.Equal(t, "jingweno", url.Owner)
	assert.Equal(t, "gh", url.Name)
	assert.Equal(t, "", url.ProjectPath())

	url, err =
		ParseURL("https://github.com/jingweno/gh/")
	assert.Equal(t, nil, err)
	assert.Equal(t, "jingweno", url.Owner)
	assert.Equal(t, "gh", url.Name)
	assert.Equal(t, "", url.ProjectPath())
}
예제 #2
0
func TestTransformCherryPickArgs(t *testing.T) {
	testConfigs := fixtures.SetupTestConfigs()
	defer testConfigs.TearDown()

	args := NewArgs([]string{})
	transformCherryPickArgs(args)
	cmds := args.Commands()
	assert.Equal(t, 1, len(cmds))

	os.Setenv("HUB_PROTOCOL", "git")
	defer os.Setenv("HUB_PROTOCOL", "")
	args = NewArgs([]string{"cherry-pick", "https://github.com/jingweno/gh/commit/a319d88#comments"})
	transformCherryPickArgs(args)

	cmds = args.Commands()
	assert.Equal(t, 2, len(cmds))
	assert.Equal(t, "git remote add -f --no-tags jingweno git://github.com/jingweno/gh.git", cmds[0].String())
	assert.Equal(t, "git cherry-pick a319d88", cmds[1].String())
}
예제 #3
0
func TestConfigService_YamlLoad(t *testing.T) {
	testConfig := fixtures.SetupTestConfigs()
	defer testConfig.TearDown()

	cc := &Config{}
	cs := &configService{
		Encoder: &yamlConfigEncoder{},
		Decoder: &yamlConfigDecoder{},
	}
	err := cs.Load(testConfig.Path, cc)
	assert.Equal(t, nil, err)

	assert.Equal(t, 1, len(cc.Hosts))
	host := cc.Hosts[0]
	assert.Equal(t, "github.com", host.Host)
	assert.Equal(t, "jingweno", host.User)
	assert.Equal(t, "123", host.AccessToken)
	assert.Equal(t, "http", host.Protocol)
}
예제 #4
0
func TestParseCherryPickProjectAndSha(t *testing.T) {
	testConfigs := fixtures.SetupTestConfigs()
	defer testConfigs.TearDown()

	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, "github.com", project.Host)
	assert.Equal(t, "https", project.Protocol)
	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)
}
예제 #5
0
파일: project_test.go 프로젝트: d2s/hub
func TestProject_NewProjectFromURL(t *testing.T) {
	testConfigs := fixtures.SetupTestConfigs()
	defer testConfigs.TearDown()

	u, _ := url.Parse("ssh://[email protected]/octokit/go-octokit.git")
	p, err := NewProjectFromURL(u)

	assert.Equal(t, nil, err)
	assert.Equal(t, "go-octokit", p.Name)
	assert.Equal(t, "octokit", p.Owner)
	assert.Equal(t, "github.com", p.Host)
	assert.Equal(t, "http", p.Protocol)

	u, _ = url.Parse("git://github.com/octokit/go-octokit.git")
	p, err = NewProjectFromURL(u)

	assert.Equal(t, nil, err)
	assert.Equal(t, "go-octokit", p.Name)
	assert.Equal(t, "octokit", p.Owner)
	assert.Equal(t, "github.com", p.Host)
	assert.Equal(t, "http", p.Protocol)

	u, _ = url.Parse("https://github.com/octokit/go-octokit")
	p, err = NewProjectFromURL(u)

	assert.Equal(t, nil, err)
	assert.Equal(t, "go-octokit", p.Name)
	assert.Equal(t, "octokit", p.Owner)
	assert.Equal(t, "github.com", p.Host)
	assert.Equal(t, "https", p.Protocol)

	u, _ = url.Parse("origin/master")
	_, err = NewProjectFromURL(u)

	assert.NotEqual(t, nil, err)
}