Update FakeCli to remove duplication in tests.
Use byte buffers by default, since that is what is done most of the time. Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
@ -16,17 +17,29 @@ type FakeCli struct {
|
||||
client client.APIClient
|
||||
configfile *configfile.ConfigFile
|
||||
out *command.OutStream
|
||||
err io.Writer
|
||||
outBuffer *bytes.Buffer
|
||||
err *bytes.Buffer
|
||||
in *command.InStream
|
||||
server command.ServerInfo
|
||||
}
|
||||
|
||||
// NewFakeCli returns a Cli backed by the fakeCli
|
||||
func NewFakeCli(client client.APIClient, out io.Writer) *FakeCli {
|
||||
// NewFakeCliWithOutput returns a Cli backed by the fakeCli
|
||||
// Deprecated: Use NewFakeCli
|
||||
func NewFakeCliWithOutput(client client.APIClient, out io.Writer) *FakeCli {
|
||||
cli := NewFakeCli(client)
|
||||
cli.out = command.NewOutStream(out)
|
||||
return cli
|
||||
}
|
||||
|
||||
// NewFakeCli returns a fake for the command.Cli interface
|
||||
func NewFakeCli(client client.APIClient) *FakeCli {
|
||||
outBuffer := new(bytes.Buffer)
|
||||
errBuffer := new(bytes.Buffer)
|
||||
return &FakeCli{
|
||||
client: client,
|
||||
out: command.NewOutStream(out),
|
||||
err: ioutil.Discard,
|
||||
out: command.NewOutStream(outBuffer),
|
||||
outBuffer: outBuffer,
|
||||
err: errBuffer,
|
||||
in: command.NewInStream(ioutil.NopCloser(strings.NewReader(""))),
|
||||
configfile: configfile.New("configfile"),
|
||||
}
|
||||
@ -38,7 +51,7 @@ func (c *FakeCli) SetIn(in *command.InStream) {
|
||||
}
|
||||
|
||||
// SetErr sets the stderr stream for the cli to the specified io.Writer
|
||||
func (c *FakeCli) SetErr(err io.Writer) {
|
||||
func (c *FakeCli) SetErr(err *bytes.Buffer) {
|
||||
c.err = err
|
||||
}
|
||||
|
||||
@ -76,3 +89,13 @@ func (c *FakeCli) ConfigFile() *configfile.ConfigFile {
|
||||
func (c *FakeCli) ServerInfo() command.ServerInfo {
|
||||
return c.server
|
||||
}
|
||||
|
||||
// OutBuffer returns the stdout buffer
|
||||
func (c *FakeCli) OutBuffer() *bytes.Buffer {
|
||||
return c.outBuffer
|
||||
}
|
||||
|
||||
// ErrBuffer Buffer returns the stderr buffer
|
||||
func (c *FakeCli) ErrBuffer() *bytes.Buffer {
|
||||
return c.err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user