Skip to content

Commit fba4f4d

Browse files
committed
InitCmdStubber
1 parent c4c967f commit fba4f4d

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

command/pr_create_test.go

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"testing"
1111

1212
"github.com/cli/cli/context"
13-
"github.com/cli/cli/utils"
1413

1514
"github.com/AlecAivazis/survey/v2"
1615
"github.com/AlecAivazis/survey/v2/core"
@@ -26,9 +25,8 @@ func TestPRCreate(t *testing.T) {
2625
} } } }
2726
`))
2827

29-
cs := CmdStubber{}
30-
teardown := utils.SetPrepareCmd(createStubbedPrepareCmd(&cs))
31-
defer teardown()
28+
cs, cmdTeardown := InitCmdStubber()
29+
defer cmdTeardown()
3230

3331
cs.Stub("") // git status
3432
cs.Stub("1234567890,commit 0\n2345678901,commit 1") // git log
@@ -65,9 +63,8 @@ func TestPRCreate_web(t *testing.T) {
6563
http := initFakeHTTP()
6664
http.StubRepoResponse("OWNER", "REPO")
6765

68-
cs := CmdStubber{}
69-
teardown := utils.SetPrepareCmd(createStubbedPrepareCmd(&cs))
70-
defer teardown()
66+
cs, cmdTeardown := InitCmdStubber()
67+
defer cmdTeardown()
7168

7269
cs.Stub("") // git status
7370
cs.Stub("1234567890,commit 0\n2345678901,commit 1") // git log
@@ -97,9 +94,8 @@ func TestPRCreate_ReportsUncommittedChanges(t *testing.T) {
9794
} } } }
9895
`))
9996

100-
cs := CmdStubber{}
101-
teardown := utils.SetPrepareCmd(createStubbedPrepareCmd(&cs))
102-
defer teardown()
97+
cs, cmdTeardown := InitCmdStubber()
98+
defer cmdTeardown()
10399

104100
cs.Stub(" M git/git.go") // git status
105101
cs.Stub("1234567890,commit 0\n2345678901,commit 1") // git log
@@ -164,9 +160,8 @@ func TestPRCreate_cross_repo_same_branch(t *testing.T) {
164160
} } } }
165161
`))
166162

167-
cs := CmdStubber{}
168-
teardown := utils.SetPrepareCmd(createStubbedPrepareCmd(&cs))
169-
defer teardown()
163+
cs, cmdTeardown := InitCmdStubber()
164+
defer cmdTeardown()
170165

171166
cs.Stub("") // git status
172167
cs.Stub("1234567890,commit 0\n2345678901,commit 1") // git log
@@ -300,9 +295,7 @@ func TestPRCreate_survey_preview_defaults(t *testing.T) {
300295
} } } }
301296
`))
302297

303-
// TODO initCmdStubber in command/testing
304-
cs := CmdStubber{}
305-
cmdTeardown := utils.SetPrepareCmd(createStubbedPrepareCmd(&cs))
298+
cs, cmdTeardown := InitCmdStubber()
306299
defer cmdTeardown()
307300

308301
cs.Stub("") // git status

command/testing.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ type CmdStubber struct {
2121
Calls []*exec.Cmd
2222
}
2323

24+
func InitCmdStubber() (*CmdStubber, func()) {
25+
cs := CmdStubber{}
26+
teardown := utils.SetPrepareCmd(createStubbedPrepareCmd(&cs))
27+
return &cs, teardown
28+
}
29+
2430
func (cs *CmdStubber) Stub(desiredOutput string) {
2531
// TODO maybe have some kind of command mapping but going simple for now
2632
cs.Stubs = append(cs.Stubs, &test.OutputStub{[]byte(desiredOutput)})

0 commit comments

Comments
 (0)