mirror of https://github.com/docker/docs.git
Merge pull request #2979 from nathanleclaire/exit_code_3
Exit with code 3 if error is during pre-create check
This commit is contained in:
commit
092c36c31a
|
@ -164,13 +164,15 @@ func runCommand(command func(commandLine CommandLine, api libmachine.API) error)
|
|||
if crashErr, ok := err.(crashreport.CrashError); ok {
|
||||
crashReporter := crashreport.NewCrashReporter(mcndirs.GetBaseDir(), context.GlobalString("bugsnag-api-token"))
|
||||
crashReporter.Send(crashErr)
|
||||
|
||||
if _, ok := crashErr.Cause.(mcnerror.ErrDuringPreCreate); ok {
|
||||
osExit(3)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if _, ok := err.(mcnerror.ErrDuringPreCreate); ok {
|
||||
osExit(3)
|
||||
} else {
|
||||
osExit(1)
|
||||
}
|
||||
osExit(1)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -200,31 +200,38 @@ func TestReturnExitCode1onError(t *testing.T) {
|
|||
|
||||
exitCode := checkErrorCodeForCommand(command)
|
||||
|
||||
assert.Equal(t, exitCode, 1)
|
||||
assert.Equal(t, 1, exitCode)
|
||||
}
|
||||
|
||||
func TestReturnExitCode3onErrorDuringPreCreate(t *testing.T) {
|
||||
command := func(commandLine CommandLine, api libmachine.API) error {
|
||||
return mcnerror.ErrDuringPreCreate{
|
||||
Cause: errors.New("foo is not bar"),
|
||||
return crashreport.CrashError{
|
||||
Cause: mcnerror.ErrDuringPreCreate{
|
||||
Cause: errors.New("foo is not bar"),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
exitCode := checkErrorCodeForCommand(command)
|
||||
|
||||
assert.Equal(t, exitCode, 3)
|
||||
assert.Equal(t, 3, exitCode)
|
||||
}
|
||||
|
||||
func checkErrorCodeForCommand(command func(commandLine CommandLine, api libmachine.API) error) int {
|
||||
var exitCode int
|
||||
var setExitCode int
|
||||
|
||||
originalOSExit := osExit
|
||||
|
||||
defer func() {
|
||||
osExit = originalOSExit
|
||||
}()
|
||||
|
||||
defer func(fnOsExit func(code int)) { osExit = fnOsExit }(osExit)
|
||||
osExit = func(code int) {
|
||||
exitCode = code
|
||||
setExitCode = code
|
||||
}
|
||||
|
||||
context := cli.NewContext(cli.NewApp(), &flag.FlagSet{}, nil)
|
||||
runCommand(command)(context)
|
||||
|
||||
return exitCode
|
||||
return setExitCode
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue