2016-12-25 16:23:35 -05:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
2017-07-05 14:19:52 -04:00
|
|
|
"bytes"
|
2016-12-25 16:23:35 -05:00
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
2017-02-27 12:39:35 -05:00
|
|
|
"strings"
|
2016-12-25 16:23:35 -05:00
|
|
|
|
2017-04-17 18:07:56 -04:00
|
|
|
"github.com/docker/cli/cli/command"
|
|
|
|
"github.com/docker/cli/cli/config/configfile"
|
2017-05-08 12:33:45 -04:00
|
|
|
"github.com/docker/docker/client"
|
2016-12-25 16:23:35 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// FakeCli emulates the default DockerCli
|
|
|
|
type FakeCli struct {
|
|
|
|
command.DockerCli
|
2017-02-27 12:39:35 -05:00
|
|
|
client client.APIClient
|
|
|
|
configfile *configfile.ConfigFile
|
2017-03-30 20:21:14 -04:00
|
|
|
out *command.OutStream
|
2017-07-05 14:19:52 -04:00
|
|
|
outBuffer *bytes.Buffer
|
|
|
|
err *bytes.Buffer
|
2017-03-30 20:21:14 -04:00
|
|
|
in *command.InStream
|
2017-06-21 15:13:44 -04:00
|
|
|
server command.ServerInfo
|
2016-12-25 16:23:35 -05:00
|
|
|
}
|
|
|
|
|
2017-07-05 14:19:52 -04:00
|
|
|
// 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)
|
2016-12-25 16:23:35 -05:00
|
|
|
return &FakeCli{
|
2017-06-21 15:13:44 -04:00
|
|
|
client: client,
|
2017-07-05 14:19:52 -04:00
|
|
|
out: command.NewOutStream(outBuffer),
|
|
|
|
outBuffer: outBuffer,
|
|
|
|
err: errBuffer,
|
2017-06-21 15:13:44 -04:00
|
|
|
in: command.NewInStream(ioutil.NopCloser(strings.NewReader(""))),
|
|
|
|
configfile: configfile.New("configfile"),
|
2016-12-25 16:23:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetIn sets the input of the cli to the specified ReadCloser
|
2017-03-30 20:21:14 -04:00
|
|
|
func (c *FakeCli) SetIn(in *command.InStream) {
|
2016-12-25 16:23:35 -05:00
|
|
|
c.in = in
|
|
|
|
}
|
|
|
|
|
2017-02-22 15:43:13 -05:00
|
|
|
// SetErr sets the stderr stream for the cli to the specified io.Writer
|
2017-07-05 14:19:52 -04:00
|
|
|
func (c *FakeCli) SetErr(err *bytes.Buffer) {
|
2017-02-27 12:39:35 -05:00
|
|
|
c.err = err
|
|
|
|
}
|
|
|
|
|
2017-07-05 14:34:16 -04:00
|
|
|
// SetConfigFile sets the "fake" config file
|
|
|
|
func (c *FakeCli) SetConfigFile(configfile *configfile.ConfigFile) {
|
2017-02-27 12:39:35 -05:00
|
|
|
c.configfile = configfile
|
|
|
|
}
|
|
|
|
|
2016-12-25 16:23:35 -05:00
|
|
|
// Client returns a docker API client
|
|
|
|
func (c *FakeCli) Client() client.APIClient {
|
|
|
|
return c.client
|
|
|
|
}
|
|
|
|
|
2017-02-27 12:39:35 -05:00
|
|
|
// Out returns the output stream (stdout) the cli should write on
|
2016-12-25 16:23:35 -05:00
|
|
|
func (c *FakeCli) Out() *command.OutStream {
|
2017-03-30 20:21:14 -04:00
|
|
|
return c.out
|
2016-12-25 16:23:35 -05:00
|
|
|
}
|
|
|
|
|
2017-02-27 12:39:35 -05:00
|
|
|
// Err returns the output stream (stderr) the cli should write on
|
|
|
|
func (c *FakeCli) Err() io.Writer {
|
|
|
|
return c.err
|
|
|
|
}
|
|
|
|
|
|
|
|
// In returns the input stream the cli will use
|
2016-12-25 16:23:35 -05:00
|
|
|
func (c *FakeCli) In() *command.InStream {
|
2017-03-30 20:21:14 -04:00
|
|
|
return c.in
|
2016-12-25 16:23:35 -05:00
|
|
|
}
|
2017-02-27 12:39:35 -05:00
|
|
|
|
|
|
|
// ConfigFile returns the cli configfile object (to get client configuration)
|
|
|
|
func (c *FakeCli) ConfigFile() *configfile.ConfigFile {
|
|
|
|
return c.configfile
|
|
|
|
}
|
2017-06-21 15:13:44 -04:00
|
|
|
|
|
|
|
// ServerInfo returns API server information for the server used by this client
|
|
|
|
func (c *FakeCli) ServerInfo() command.ServerInfo {
|
|
|
|
return c.server
|
|
|
|
}
|
2017-07-05 14:19:52 -04:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|