From bb87f4a2fbe56de4f299cc070de9ef550009b90f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 13 Nov 2019 19:25:02 +0100 Subject: [PATCH] Add `pr create` test for git clean state --- command/pr_create_test.go | 43 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/command/pr_create_test.go b/command/pr_create_test.go index 7453a0e1f..191043be3 100644 --- a/command/pr_create_test.go +++ b/command/pr_create_test.go @@ -37,7 +37,7 @@ func TestPrCreateHelperProcess(*testing.T) { os.Exit(0) } -func TestReportsUncommittedChanges(t *testing.T) { +func TestPRCreate(t *testing.T) { ctx := context.NewBlank() ctx.SetBranch("feature") ctx.SetRemotes(map[string]string{ @@ -60,12 +60,11 @@ func TestReportsUncommittedChanges(t *testing.T) { `)) origGitCommand := git.GitCommand + git.GitCommand = test.StubExecCommand("TestPrCreateHelperProcess", "clean") defer func() { git.GitCommand = origGitCommand }() - git.GitCommand = test.StubExecCommand("TestPrCreateHelperProcess", "dirty") - out := bytes.Buffer{} prCreateCmd.SetOut(&out) @@ -93,6 +92,44 @@ func TestReportsUncommittedChanges(t *testing.T) { eq(t, reqBody.Variables.Input.BaseRefName, "master") eq(t, reqBody.Variables.Input.HeadRefName, "feature") + eq(t, out.String(), "https://github.com/OWNER/REPO/pull/12\n") +} + +func TestPRCreate_ReportsUncommittedChanges(t *testing.T) { + ctx := context.NewBlank() + ctx.SetBranch("feature") + ctx.SetRemotes(map[string]string{ + "origin": "OWNER/REPO", + }) + initContext = func() context.Context { + return ctx + } + http := initFakeHTTP() + + http.StubResponse(200, bytes.NewBufferString(` + { "data": { "repository": { + "id": "REPOID" + } } } + `)) + http.StubResponse(200, bytes.NewBufferString(` + { "data": { "createPullRequest": { "pullRequest": { + "URL": "https://github.com/OWNER/REPO/pull/12" + } } } } + `)) + + origGitCommand := git.GitCommand + git.GitCommand = test.StubExecCommand("TestPrCreateHelperProcess", "dirty") + defer func() { + git.GitCommand = origGitCommand + }() + + out := bytes.Buffer{} + prCreateCmd.SetOut(&out) + + RootCmd.SetArgs([]string{"pr", "create", "-t", "mytitle", "-b", "mybody"}) + _, err := prCreateCmd.ExecuteC() + eq(t, err, nil) + eq(t, out.String(), `Warning: 1 uncommitted change https://github.com/OWNER/REPO/pull/12 `)