Review feedback

This commit is contained in:
Tom Wilkie
2015-08-27 16:34:56 +00:00
parent 55c77c6a37
commit 903a51397b
7 changed files with 47 additions and 37 deletions

View File

@@ -5,36 +5,16 @@ import (
"io"
"io/ioutil"
"os"
"os/exec"
"github.com/weaveworks/scope/common/exec"
)
// Cmd is a hook for mocking
type Cmd interface {
StdoutPipe() (io.ReadCloser, error)
Start() error
Wait() error
Process() *os.Process
}
// Command is a hook for mocking
var Command = func(name string, args ...string) Cmd {
return &realCmd{exec.Command(name, args...)}
}
type realCmd struct {
*exec.Cmd
}
func (c *realCmd) Process() *os.Process {
return c.Cmd.Process
}
type mockCmd struct {
io.ReadCloser
}
// NewMockCmdString creates a new mock Cmd which has s on its stdout pipe
func NewMockCmdString(s string) Cmd {
func NewMockCmdString(s string) exec.Cmd {
return &mockCmd{
struct {
io.Reader
@@ -47,7 +27,7 @@ func NewMockCmdString(s string) Cmd {
}
// NewMockCmd creates a new mock Cmd with rc as its stdout pipe
func NewMockCmd(rc io.ReadCloser) Cmd {
func NewMockCmd(rc io.ReadCloser) exec.Cmd {
return &mockCmd{rc}
}