Skip to content

Commit dd1e2a2

Browse files
committed
add StubError to CmdStubber
1 parent 88cf6ce commit dd1e2a2

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

command/pr_checkout_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ func TestPRCheckout_differentRepo_existingBranch(t *testing.T) {
350350
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
351351
switch strings.Join(cmd.Args, " ") {
352352
case "git config branch.feature.merge":
353-
return &test.OutputStub{[]byte("refs/heads/feature\n")}
353+
return &test.OutputStub{[]byte("refs/heads/feature\n"), nil}
354354
default:
355355
ranCommands = append(ranCommands, cmd.Args)
356356
return &test.OutputStub{}
@@ -400,7 +400,7 @@ func TestPRCheckout_differentRepo_currentBranch(t *testing.T) {
400400
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
401401
switch strings.Join(cmd.Args, " ") {
402402
case "git config branch.feature.merge":
403-
return &test.OutputStub{[]byte("refs/heads/feature\n")}
403+
return &test.OutputStub{[]byte("refs/heads/feature\n"), nil}
404404
default:
405405
ranCommands = append(ranCommands, cmd.Args)
406406
return &test.OutputStub{}

command/pr_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func TestPRStatus_fork(t *testing.T) {
112112
switch strings.Join(cmd.Args, " ") {
113113
case `git config --get-regexp ^branch\.blueberries\.(remote|merge)$`:
114114
return &test.OutputStub{[]byte(`branch.blueberries.remote origin
115-
branch.blueberries.merge refs/heads/blueberries`)}
115+
branch.blueberries.merge refs/heads/blueberries`), nil}
116116
default:
117117
panic("not implemented")
118118
}

git/git_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func Test_UncommittedChangeCount(t *testing.T) {
2727

2828
for _, v := range cases {
2929
_ = run.SetPrepareCmd(func(*exec.Cmd) run.Runnable {
30-
return &test.OutputStub{[]byte(v.Output)}
30+
return &test.OutputStub{[]byte(v.Output), nil}
3131
})
3232
ucc, _ := UncommittedChangeCount()
3333

test/helpers.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package test
22

33
import (
4+
"errors"
45
"fmt"
56
"os/exec"
67

@@ -9,14 +10,21 @@ import (
910

1011
// OutputStub implements a simple utils.Runnable
1112
type OutputStub struct {
12-
Out []byte
13+
Out []byte
14+
Error error
1315
}
1416

1517
func (s OutputStub) Output() ([]byte, error) {
18+
if s.Error != nil {
19+
return s.Out, s.Error
20+
}
1621
return s.Out, nil
1722
}
1823

1924
func (s OutputStub) Run() error {
25+
if s.Error != nil {
26+
return s.Error
27+
}
2028
return nil
2129
}
2230

@@ -34,7 +42,12 @@ func InitCmdStubber() (*CmdStubber, func()) {
3442

3543
func (cs *CmdStubber) Stub(desiredOutput string) {
3644
// TODO maybe have some kind of command mapping but going simple for now
37-
cs.Stubs = append(cs.Stubs, &OutputStub{[]byte(desiredOutput)})
45+
cs.Stubs = append(cs.Stubs, &OutputStub{[]byte(desiredOutput), nil})
46+
}
47+
48+
func (cs *CmdStubber) StubError(msg string) {
49+
// TODO consider handling CmdErr instead of a raw error
50+
cs.Stubs = append(cs.Stubs, &OutputStub{[]byte{}, errors.New(msg)})
3851
}
3952

4053
func createStubbedPrepareCmd(cs *CmdStubber) func(*exec.Cmd) run.Runnable {

0 commit comments

Comments
 (0)