예제 #1
0
func checkSavedReportCrashOption(t *testing.T, always bool, confirm, expected string) {
	repo := fixtures.SetupTestRepo()
	defer repo.TearDown()

	saveReportConfiguration(confirm, always)
	assert.Equal(t, expected, reportCrashConfig())
}
예제 #2
0
파일: git_test.go 프로젝트: DarinM223/hub
func TestGitDir(t *testing.T) {
	repo := fixtures.SetupTestRepo()
	defer repo.TearDown()

	gitDir, _ := Dir()
	assert.T(t, strings.Contains(gitDir, ".git"))
}
예제 #3
0
파일: git_test.go 프로젝트: DarinM223/hub
func TestGitShow(t *testing.T) {
	repo := fixtures.SetupTestRepo()
	defer repo.TearDown()

	output, err := Show("9b5a719a3d76ac9dc2fa635d9b1f34fd73994c06")
	assert.Equal(t, nil, err)
	assert.Equal(t, "First comment\n\nMore comment", output)
}
예제 #4
0
파일: git_test.go 프로젝트: DarinM223/hub
func TestGitLog(t *testing.T) {
	repo := fixtures.SetupTestRepo()
	defer repo.TearDown()

	log, err := Log("08f4b7b6513dffc6245857e497cfd6101dc47818", "9b5a719a3d76ac9dc2fa635d9b1f34fd73994c06")
	assert.Equal(t, nil, err)
	assert.NotEqual(t, "", log)
}
예제 #5
0
파일: git_test.go 프로젝트: DarinM223/hub
func TestGitEditor(t *testing.T) {
	repo := fixtures.SetupTestRepo()
	defer repo.TearDown()

	SetGlobalConfig("core.editor", "foo")
	gitEditor, err := Editor()
	assert.Equal(t, nil, err)
	assert.Equal(t, "foo", gitEditor)
}
예제 #6
0
파일: git_test.go 프로젝트: DarinM223/hub
func TestGitRef(t *testing.T) {
	repo := fixtures.SetupTestRepo()
	defer repo.TearDown()

	ref := "08f4b7b6513dffc6245857e497cfd6101dc47818"
	gitRef, err := Ref(ref)
	assert.Equal(t, nil, err)
	assert.Equal(t, ref, gitRef)
}
예제 #7
0
func checkSavedAutoUpdateOption(t *testing.T, always bool, confirm, expected string) {
	EnableAutoUpdate = true
	repo := fixtures.SetupTestRepo()
	defer repo.TearDown()

	saveAutoUpdateConfiguration(confirm, always)
	assert.Equal(t, expected, autoUpdateConfig())
	EnableAutoUpdate = false
}
예제 #8
0
파일: git_test.go 프로젝트: DarinM223/hub
func TestGitRefList(t *testing.T) {
	repo := fixtures.SetupTestRepo()
	defer repo.TearDown()

	refList, err := RefList("08f4b7b6513dffc6245857e497cfd6101dc47818", "9b5a719a3d76ac9dc2fa635d9b1f34fd73994c06")
	assert.Equal(t, nil, err)
	assert.Equal(t, 1, len(refList))

	assert.Equal(t, "9b5a719a3d76ac9dc2fa635d9b1f34fd73994c06", refList[0])
}
예제 #9
0
func TestRemotes(t *testing.T) {
	repo := fixtures.SetupTestRepo()
	defer repo.TearDown()

	type remote struct {
		name    string
		url     string
		pushUrl string
	}
	testCases := map[string]remote{
		"testremote1": {
			"testremote1",
			"https://example.com/test1/project1.git",
			"no_push",
		},
		"testremote2": {
			"testremote2",
			"[email protected]:test2/project2.git",
			"http://example.com/project.git",
		},
		"testremote3": {
			"testremote3",
			"https://example.com/test1/project2.git",
			"",
		},
	}

	for _, tc := range testCases {
		repo.AddRemote(tc.name, tc.url, tc.pushUrl)
	}

	remotes, err := Remotes()
	assert.Equal(t, nil, err)

	// In addition to the remotes we added to the repo, repo will
	// also have an additional remote "origin". So add it to the
	// expected cases to test.
	wantCases := map[string]struct{}{
		fmt.Sprintf("origin	%s (fetch)", repo.Remote): {},
		fmt.Sprintf("origin	%s (push)", repo.Remote): {},
		"testremote1	https://example.com/test1/project1.git (fetch)": {},
		"testremote1	no_push (push)": {},
		"testremote2	[email protected]:test2/project2.git (fetch)": {},
		"testremote2	http://example.com/project.git (push)": {},
		"testremote3	https://example.com/test1/project2.git (fetch)": {},
		"testremote3	https://example.com/test1/project2.git (push)": {},
	}

	assert.Equal(t, len(remotes), len(wantCases))
	for _, got := range remotes {
		if _, ok := wantCases[got]; !ok {
			t.Errorf("Unexpected remote: %s", got)
		}
	}
}
예제 #10
0
func TestGitHubRepo_OriginRemote(t *testing.T) {
	repo := fixtures.SetupTestRepo()
	defer repo.TearDown()

	localRepo, _ := LocalRepo()
	gitRemote, _ := localRepo.OriginRemote()
	assert.Equal(t, "origin", gitRemote.Name)

	u, _ := url.Parse(repo.Remote)
	assert.Equal(t, u, gitRemote.URL)
}
예제 #11
0
파일: template_test.go 프로젝트: github/hub
func TestGithubTemplate_withoutTemplate(t *testing.T) {
	repo := fixtures.SetupTestRepo()
	defer repo.TearDown()

	pwd, _ := os.Getwd()
	tpl, err := ReadTemplate(PullRequestTemplate, pwd)
	assert.Equal(t, nil, err)
	assert.Equal(t, "", tpl)

	tpl, err = ReadTemplate(IssueTemplate, pwd)
	assert.Equal(t, nil, err)
	assert.Equal(t, "", tpl)
}
예제 #12
0
파일: template_test.go 프로젝트: github/hub
func TestGithubTemplate_withInvalidTemplate(t *testing.T) {
	repo := fixtures.SetupTestRepo()
	defer repo.TearDown()

	addGithubTemplates(repo, map[string]string{"dir": "invalidPath"})

	pwd, _ := os.Getwd()
	tpl, err := ReadTemplate(PullRequestTemplate, pwd)
	assert.Equal(t, nil, err)
	assert.Equal(t, "", tpl)

	tpl, err = ReadTemplate(IssueTemplate, pwd)
	assert.Equal(t, nil, err)
	assert.Equal(t, "", tpl)
}
예제 #13
0
파일: template_test.go 프로젝트: github/hub
func TestGithubTemplate_WithTemplateInGithubDir(t *testing.T) {
	repo := fixtures.SetupTestRepo()
	defer repo.TearDown()

	addGithubTemplates(repo, map[string]string{"dir": githubTemplateDir})

	pwd, _ := os.Getwd()
	tpl, err := ReadTemplate(PullRequestTemplate, pwd)
	assert.Equal(t, nil, err)
	assert.Equal(t, prContent, tpl)

	tpl, err = ReadTemplate(IssueTemplate, pwd)
	assert.Equal(t, nil, err)
	assert.Equal(t, issueContent, tpl)
}
예제 #14
0
func TestGithubRemote_ColonSlash(t *testing.T) {
	repo := fixtures.SetupTestRepo()
	defer repo.TearDown()

	remoteName := "upstream"
	repo.AddRemote(remoteName, "[email protected]:/fatso83/my-project.git", "")

	remotes, err := Remotes()
	assert.Equal(t, nil, err)
	assert.Equal(t, len(remotes), 2)
	assert.Equal(t, remotes[0].Name, remoteName)
	assert.Equal(t, remotes[0].URL.Scheme, "ssh")
	assert.Equal(t, remotes[0].URL.Host, "github.com")
	assert.Equal(t, remotes[0].URL.Path, "/fatso83/my-project.git")
	assert.Equal(t, remotes[1].Name, "origin")
	assert.Equal(t, remotes[1].URL.Path, repo.Remote)
}
예제 #15
0
func TestGithubRemote_SshPort(t *testing.T) {
	repo := fixtures.SetupTestRepo()
	defer repo.TearDown()

	remoteName := "upstream"
	repo.AddRemote(remoteName, "ssh://[email protected]:22/hakatashi/dotfiles.git", "")

	remotes, err := Remotes()
	assert.Equal(t, nil, err)
	assert.Equal(t, len(remotes), 2)
	assert.Equal(t, remotes[0].Name, remoteName)
	assert.Equal(t, remotes[0].URL.Scheme, "ssh")
	assert.Equal(t, remotes[0].URL.Host, "github.com")
	assert.Equal(t, remotes[0].URL.Path, "/hakatashi/dotfiles.git")
	assert.Equal(t, remotes[1].Name, "origin")
	assert.Equal(t, remotes[1].URL.Path, repo.Remote)
}
예제 #16
0
func TestGithubRemote_GitPlusSsh(t *testing.T) {
	repo := fixtures.SetupTestRepo()
	defer repo.TearDown()

	remoteName := "upstream"
	repo.AddRemote(remoteName, "git+ssh://[email protected]/frozencemetery/python-gssapi", "")

	remotes, err := Remotes()
	assert.Equal(t, nil, err)
	assert.Equal(t, len(remotes), 2)
	assert.Equal(t, remotes[0].Name, remoteName)
	assert.Equal(t, remotes[0].URL.Scheme, "ssh")
	assert.Equal(t, remotes[0].URL.Host, "github.com")
	assert.Equal(t, remotes[0].URL.Path, "/frozencemetery/python-gssapi")
	assert.Equal(t, remotes[1].Name, "origin")
	assert.Equal(t, remotes[1].URL.Path, repo.Remote)
}
예제 #17
0
파일: git_test.go 프로젝트: DarinM223/hub
func TestGitConfig(t *testing.T) {
	repo := fixtures.SetupTestRepo()
	defer repo.TearDown()

	v, err := GlobalConfig("hub.test")
	assert.NotEqual(t, nil, err)

	SetGlobalConfig("hub.test", "1")
	v, err = GlobalConfig("hub.test")
	assert.Equal(t, nil, err)
	assert.Equal(t, "1", v)

	SetGlobalConfig("hub.test", "")
	v, err = GlobalConfig("hub.test")
	assert.Equal(t, nil, err)
	assert.Equal(t, "", v)
}
예제 #18
0
func TestGithubRepo_Remotes(t *testing.T) {
	repo := fixtures.SetupTestRepo()
	defer repo.TearDown()

	remoteName := "upstream"
	repo.AddRemote(remoteName, "[email protected]:test/project.git", "no_push")

	remotes, err := Remotes()
	assert.Equal(t, nil, err)
	assert.Equal(t, len(remotes), 2)
	assert.Equal(t, remotes[0].Name, remoteName)
	assert.Equal(t, remotes[0].URL.Scheme, "ssh")
	assert.Equal(t, remotes[0].URL.Host, "example.com")
	assert.Equal(t, remotes[0].URL.Path, "/test/project.git")
	assert.Equal(t, remotes[1].Name, "origin")
	assert.Equal(t, remotes[1].URL.Path, repo.Remote)
}
예제 #19
0
func TestGitEditor(t *testing.T) {
	repo := fixtures.SetupTestRepo()
	editor := os.Getenv("GIT_EDITOR")
	if err := os.Unsetenv("GIT_EDITOR"); err != nil {
		t.Fatal(err)
	}
	defer func() {
		repo.TearDown()
		if err := os.Setenv("GIT_EDITOR", editor); err != nil {
			t.Fatal(err)
		}
	}()

	SetGlobalConfig("core.editor", "foo")
	gitEditor, err := Editor()
	assert.Equal(t, nil, err)
	assert.Equal(t, "foo", gitEditor)
}
예제 #20
0
파일: template_test.go 프로젝트: github/hub
func TestGithubTemplate_WithMarkdown(t *testing.T) {
	repo := fixtures.SetupTestRepo()
	defer repo.TearDown()

	addGithubTemplates(repo,
		map[string]string{
			"prTemplate":    PullRequestTemplate + ".md",
			"issueTemplate": IssueTemplate + ".md",
		})

	pwd, _ := os.Getwd()
	tpl, err := ReadTemplate(PullRequestTemplate, pwd)
	assert.Equal(t, nil, err)
	assert.Equal(t, prContent, tpl)

	tpl, err = ReadTemplate(IssueTemplate, pwd)
	assert.Equal(t, nil, err)
	assert.Equal(t, issueContent, tpl)
}
예제 #21
0
파일: git_test.go 프로젝트: pcorpet/hub
func TestGitEditor(t *testing.T) {
	repo := fixtures.SetupTestRepo()
	editor := os.Getenv("GIT_EDITOR")
	if err := os.Unsetenv("GIT_EDITOR"); err != nil {
		t.Fatal(err)
	}
	defer func() {
		repo.TearDown()
		if err := os.Setenv("GIT_EDITOR", editor); err != nil {
			t.Fatal(err)
		}
		os.Unsetenv("FOO")
		os.Unsetenv("BAR")
	}()

	os.Setenv("FOO", "hello")
	os.Setenv("BAR", "happy world")

	SetGlobalConfig("core.editor", `$FOO "${BAR}"`)
	gitEditor, err := Editor()
	assert.Equal(t, nil, err)
	assert.Equal(t, `hello "happy world"`, gitEditor)
}