fix(pr create & stubs): handle exitcode in stubs
This commit is contained in:
parent
188e1388b3
commit
bf7bf99f54
2 changed files with 15 additions and 4 deletions
|
|
@ -43,10 +43,21 @@ func (gc *Command) Output() ([]byte, error) {
|
|||
out, err := run.PrepareCmd(gc.Cmd).Output()
|
||||
if err != nil {
|
||||
ge := GitError{err: err}
|
||||
|
||||
// In real implementation, this should be an exec.ExitError, as below,
|
||||
// but the tests use a different type because exec.ExitError are difficult
|
||||
// to create. We want to get the exit code and stderr, but stderr
|
||||
// is not a method and so tests can't access it.
|
||||
// THIS MEANS THAT TESTS WILL NOT CORRECTLY HAVE STDERR SET,
|
||||
// but at least tests can get the exit code.
|
||||
var exitErrorWithExitCode errWithExitCode
|
||||
if errors.As(err, &exitErrorWithExitCode) {
|
||||
ge.ExitCode = exitErrorWithExitCode.ExitCode()
|
||||
}
|
||||
|
||||
var exitError *exec.ExitError
|
||||
if errors.As(err, &exitError) {
|
||||
ge.Stderr = string(exitError.Stderr)
|
||||
ge.ExitCode = exitError.ExitCode()
|
||||
}
|
||||
err = &ge
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1304,9 +1304,9 @@ func Test_createRun(t *testing.T) {
|
|||
},
|
||||
customPushDestination: true,
|
||||
cmdStubs: func(cs *run.CommandStubber) {
|
||||
cs.Register("git rev-parse --abbrev-ref feature@{push}", 0, "")
|
||||
cs.Register("git config remote.pushDefault", 0, "")
|
||||
cs.Register("git config push.default", 0, "")
|
||||
cs.Register("git rev-parse --abbrev-ref feature@{push}", 1, "fatal: not a git repository (or any of the parent directories): .git")
|
||||
cs.Register("git config remote.pushDefault", 1, "")
|
||||
cs.Register("git config push.default", 1, "")
|
||||
},
|
||||
expectedOut: "https://github.com/OWNER/REPO/pull/12\n",
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue