Skip to content

Commit bb87f4a

Browse files
committed
Add pr create test for git clean state
1 parent e3e8647 commit bb87f4a

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

command/pr_create_test.go

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestPrCreateHelperProcess(*testing.T) {
3737
os.Exit(0)
3838
}
3939

40-
func TestReportsUncommittedChanges(t *testing.T) {
40+
func TestPRCreate(t *testing.T) {
4141
ctx := context.NewBlank()
4242
ctx.SetBranch("feature")
4343
ctx.SetRemotes(map[string]string{
@@ -60,12 +60,11 @@ func TestReportsUncommittedChanges(t *testing.T) {
6060
`))
6161

6262
origGitCommand := git.GitCommand
63+
git.GitCommand = test.StubExecCommand("TestPrCreateHelperProcess", "clean")
6364
defer func() {
6465
git.GitCommand = origGitCommand
6566
}()
6667

67-
git.GitCommand = test.StubExecCommand("TestPrCreateHelperProcess", "dirty")
68-
6968
out := bytes.Buffer{}
7069
prCreateCmd.SetOut(&out)
7170

@@ -93,6 +92,44 @@ func TestReportsUncommittedChanges(t *testing.T) {
9392
eq(t, reqBody.Variables.Input.BaseRefName, "master")
9493
eq(t, reqBody.Variables.Input.HeadRefName, "feature")
9594

95+
eq(t, out.String(), "https://github.com/OWNER/REPO/pull/12\n")
96+
}
97+
98+
func TestPRCreate_ReportsUncommittedChanges(t *testing.T) {
99+
ctx := context.NewBlank()
100+
ctx.SetBranch("feature")
101+
ctx.SetRemotes(map[string]string{
102+
"origin": "OWNER/REPO",
103+
})
104+
initContext = func() context.Context {
105+
return ctx
106+
}
107+
http := initFakeHTTP()
108+
109+
http.StubResponse(200, bytes.NewBufferString(`
110+
{ "data": { "repository": {
111+
"id": "REPOID"
112+
} } }
113+
`))
114+
http.StubResponse(200, bytes.NewBufferString(`
115+
{ "data": { "createPullRequest": { "pullRequest": {
116+
"URL": "https://github.com/OWNER/REPO/pull/12"
117+
} } } }
118+
`))
119+
120+
origGitCommand := git.GitCommand
121+
git.GitCommand = test.StubExecCommand("TestPrCreateHelperProcess", "dirty")
122+
defer func() {
123+
git.GitCommand = origGitCommand
124+
}()
125+
126+
out := bytes.Buffer{}
127+
prCreateCmd.SetOut(&out)
128+
129+
RootCmd.SetArgs([]string{"pr", "create", "-t", "mytitle", "-b", "mybody"})
130+
_, err := prCreateCmd.ExecuteC()
131+
eq(t, err, nil)
132+
96133
eq(t, out.String(), `Warning: 1 uncommitted change
97134
https://github.com/OWNER/REPO/pull/12
98135
`)

0 commit comments

Comments
 (0)