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
|
|
|
|
2017-04-17 18:07:56 -04:00
|
|
|
"github.com/docker/cli/cli/command"
|
|
|
|
"github.com/docker/cli/cli/config/configfile"
|
2017-03-30 20:21:14 -04:00
|
|
|
"github.com/docker/cli/cli/config/credentials"
|
2017-04-17 18:07:56 -04:00
|
|
|
"github.com/docker/cli/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-02-27 12:39:35 -05:00
|
|
|
err io.Writer
|
2017-03-30 20:21:14 -04:00
|
|
|
in *command.InStream
|
|
|
|
store credentials.Store
|
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,
|
2017-03-30 20:21:14 -04:00
|
|
|
out: command.NewOutStream(out),
|
2017-02-27 12:39:35 -05:00
|
|
|
err: ioutil.Discard,
|
2017-03-30 20:21:14 -04:00
|
|
|
in: command.NewInStream(ioutil.NopCloser(strings.NewReader(""))),
|
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-02-27 12:39:35 -05:00
|
|
|
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 {
|
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-03-30 20:21:14 -04:00
|
|
|
|
|
|
|
// CredentialsStore returns the fake store the cli will use
|
|
|
|
func (c *FakeCli) CredentialsStore(serverAddress string) credentials.Store {
|
|
|
|
if c.store == nil {
|
|
|
|
c.store = NewFakeStore()
|
|
|
|
}
|
|
|
|
return c.store
|
|
|
|
}
|