cli.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Package test is a test-only package that can be used by other cli package to write unit test
  2. package test
  3. import (
  4. "io"
  5. "io/ioutil"
  6. "github.com/docker/docker/cli/command"
  7. "github.com/docker/docker/client"
  8. "strings"
  9. )
  10. // FakeCli emulates the default DockerCli
  11. type FakeCli struct {
  12. command.DockerCli
  13. client client.APIClient
  14. out io.Writer
  15. in io.ReadCloser
  16. }
  17. // NewFakeCli returns a Cli backed by the fakeCli
  18. func NewFakeCli(client client.APIClient, out io.Writer) *FakeCli {
  19. return &FakeCli{
  20. client: client,
  21. out: out,
  22. in: ioutil.NopCloser(strings.NewReader("")),
  23. }
  24. }
  25. // SetIn sets the input of the cli to the specified ReadCloser
  26. func (c *FakeCli) SetIn(in io.ReadCloser) {
  27. c.in = in
  28. }
  29. // Client returns a docker API client
  30. func (c *FakeCli) Client() client.APIClient {
  31. return c.client
  32. }
  33. // Out returns the output stream the cli should write on
  34. func (c *FakeCli) Out() *command.OutStream {
  35. return command.NewOutStream(c.out)
  36. }
  37. // In returns thi input stream the cli will use
  38. func (c *FakeCli) In() *command.InStream {
  39. return command.NewInStream(c.in)
  40. }