Files
docker-cli/components/engine/cli/internal/test/cli.go
Vincent Demeester f6ad06ceb6 Add some unit tests to the node and swarm cli code
Start work on adding unit tests to our cli code in order to have to
write less costly integration test.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Upstream-commit: f151c297eb268e22dc1eb36ded0e356885f40739
Component: engine
2017-01-09 18:30:15 +01:00

49 lines
1.1 KiB
Go

// Package test is a test-only package that can be used by other cli package to write unit test
package test
import (
"io"
"io/ioutil"
"github.com/docker/docker/cli/command"
"github.com/docker/docker/client"
"strings"
)
// FakeCli emulates the default DockerCli
type FakeCli struct {
command.DockerCli
client client.APIClient
out io.Writer
in io.ReadCloser
}
// NewFakeCli returns a Cli backed by the fakeCli
func NewFakeCli(client client.APIClient, out io.Writer) *FakeCli {
return &FakeCli{
client: client,
out: out,
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
}
// Client returns a docker API client
func (c *FakeCli) Client() client.APIClient {
return c.client
}
// Out returns the output stream the cli should write on
func (c *FakeCli) Out() *command.OutStream {
return command.NewOutStream(c.out)
}
// In returns thi input stream the cli will use
func (c *FakeCli) In() *command.InStream {
return command.NewInStream(c.in)
}