github.com/flavio/docker@v0.1.3-0.20170117145210-f63d1a6eec47/cli/internal/test/cli.go (about)

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