Include stderr in exit errors.
parent
39dfb0c887
commit
258104ae32
|
@ -15,6 +15,7 @@
|
||||||
package samples
|
package samples
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -49,6 +50,8 @@ type SubprocessTest struct {
|
||||||
ToClose []io.Closer
|
ToClose []io.Closer
|
||||||
|
|
||||||
mountCmd *exec.Cmd
|
mountCmd *exec.Cmd
|
||||||
|
mountStdout bytes.Buffer
|
||||||
|
mountStderr bytes.Buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mount the file system and initialize the other exported fields of the
|
// Mount the file system and initialize the other exported fields of the
|
||||||
|
@ -109,17 +112,6 @@ func buildMountSample() (toolPath string, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Invoke mount_sample, returning a running command.
|
|
||||||
func invokeMountSample(path string, args []string) (cmd *exec.Cmd, err error) {
|
|
||||||
cmd = exec.Command(path, args...)
|
|
||||||
if err = cmd.Start(); err != nil {
|
|
||||||
err = fmt.Errorf("Start: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Like SetUp, but doens't panic.
|
// Like SetUp, but doens't panic.
|
||||||
func (t *SubprocessTest) initialize() (err error) {
|
func (t *SubprocessTest) initialize() (err error) {
|
||||||
// Initialize the context.
|
// Initialize the context.
|
||||||
|
@ -139,13 +131,22 @@ func (t *SubprocessTest) initialize() (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Invoke it.
|
// Set up a command.
|
||||||
args := []string{"--type", t.MountType}
|
args := []string{
|
||||||
|
toolPath,
|
||||||
|
"--type",
|
||||||
|
t.MountType,
|
||||||
|
}
|
||||||
|
|
||||||
args = append(args, t.MountFlags...)
|
args = append(args, t.MountFlags...)
|
||||||
|
|
||||||
t.mountCmd, err = invokeMountSample(toolPath, args)
|
t.mountCmd = exec.Command(toolPath, args...)
|
||||||
if err != nil {
|
t.mountCmd.Stdout = &t.mountStdout
|
||||||
err = fmt.Errorf("invokeMountSample: %v", err)
|
t.mountCmd.Stderr = &t.mountStderr
|
||||||
|
|
||||||
|
// Start it.
|
||||||
|
if err = t.mountCmd.Start(); err != nil {
|
||||||
|
err = fmt.Errorf("mountCmd.Start: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,7 +202,16 @@ func (t *SubprocessTest) destroy() (err error) {
|
||||||
|
|
||||||
// Wait for the subprocess.
|
// Wait for the subprocess.
|
||||||
if err = t.mountCmd.Wait(); err != nil {
|
if err = t.mountCmd.Wait(); err != nil {
|
||||||
err = fmt.Errorf("Cmd.Wait: %v", err)
|
if exitErr, ok := err.(*exec.ExitError); ok {
|
||||||
|
err = fmt.Errorf(
|
||||||
|
"mount_sample exited with %v. Stderr:\n%s",
|
||||||
|
exitErr,
|
||||||
|
t.mountStderr.String())
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = fmt.Errorf("mountCmd.Wait: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue