2016-12-25 16:23:35 -05:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
2017-02-27 12:39:35 -05:00
|
|
|
"strings"
|
2016-12-25 16:23:35 -05:00
|
|
|
|
|
|
|
"github.com/docker/docker/cli/command"
|
2017-02-27 12:39:35 -05:00
|
|
|
"github.com/docker/docker/cli/config/configfile"
|
2016-12-25 16:23:35 -05:00
|
|
|
"github.com/docker/docker/client"
|
|
|
|
)
|
|
|
|
|
|
|
|
// FakeCli emulates the default DockerCli
|
|
|
|
type FakeCli struct {
|
|
|
|
command.DockerCli
|
2017-02-27 12:39:35 -05:00
|
|
|
client client.APIClient
|
|
|
|
configfile *configfile.ConfigFile
|
|
|
|
out io.Writer
|
|
|
|
err io.Writer
|
|
|
|
in io.ReadCloser
|
2016-12-25 16:23:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewFakeCli returns a Cli backed by the fakeCli
|
|
|
|
func NewFakeCli(client client.APIClient, out io.Writer) *FakeCli {
|
|
|
|
return &FakeCli{
|
|
|
|
client: client,
|
|
|
|
out: out,
|
2017-02-27 12:39:35 -05:00
|
|
|
err: ioutil.Discard,
|
2016-12-25 16:23:35 -05:00
|
|
|
in: ioutil.NopCloser(strings.NewReader("")),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetIn sets the input of the cli to the specified ReadCloser
|
|
|
|
func (c *FakeCli) SetIn(in io.ReadCloser) {
|
|
|
|
c.in = in
|
|
|
|
}
|
|
|
|
|
2017-02-27 12:39:35 -05:00
|
|
|
// SetErr sets the standard error stream th cli should write on
|
|
|
|
func (c *FakeCli) SetErr(err io.Writer) {
|
|
|
|
c.err = err
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetConfigfile sets the "fake" config file
|
|
|
|
func (c *FakeCli) SetConfigfile(configfile *configfile.ConfigFile) {
|
|
|
|
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 {
|
|
|
|
return command.NewOutStream(c.out)
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
return command.NewInStream(c.in)
|
|
|
|
}
|
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
|
|
|
|
}
|