package test
import "github.com/docker/cli/internal/test"
Package test is a test-only package that can be used by other cli package to write unit test.
It as an internal package and cannot be used outside of github.com/docker/cli package.
Index ¶
- func NewWriterWithHook(actualWriter io.Writer, hook func([]byte)) *writerWithHook
- func RandomID() string
- func TerminatePrompt(ctx context.Context, t *testing.T, cmd *cobra.Command, cli *FakeCli)
- type FakeCli
- func NewFakeCli(apiClient client.APIClient, opts ...func(*FakeCli)) *FakeCli
- func (*FakeCli) BuildKitEnabled() (bool, error)
- func (c *FakeCli) Client() client.APIClient
- func (c *FakeCli) ConfigFile() *configfile.ConfigFile
- func (c *FakeCli) ContextStore() store.Store
- func (c *FakeCli) CurrentContext() string
- func (*FakeCli) CurrentVersion() string
- func (c *FakeCli) DockerEndpoint() docker.Endpoint
- func (c *FakeCli) Err() *streams.Out
- func (c *FakeCli) ErrBuffer() *bytes.Buffer
- func (c *FakeCli) In() *streams.In
- func (c *FakeCli) ManifestStore() manifeststore.Store
- func (c *FakeCli) Out() *streams.Out
- func (c *FakeCli) OutBuffer() *bytes.Buffer
- func (c *FakeCli) RegistryClient(bool) registryclient.RegistryClient
- func (c *FakeCli) ResetOutputBuffers()
- func (c *FakeCli) ServerInfo() command.ServerInfo
- func (c *FakeCli) SetConfigFile(configFile *configfile.ConfigFile)
- func (c *FakeCli) SetContextStore(contextStore store.Store)
- func (c *FakeCli) SetCurrentContext(name string)
- func (c *FakeCli) SetDockerEndpoint(ep docker.Endpoint)
- func (c *FakeCli) SetErr(err *streams.Out)
- func (c *FakeCli) SetIn(in *streams.In)
- func (c *FakeCli) SetManifestStore(manifestStore manifeststore.Store)
- func (c *FakeCli) SetOut(out *streams.Out)
- func (c *FakeCli) SetRegistryClient(registryClient registryclient.RegistryClient)
Functions ¶
func NewWriterWithHook ¶
NewWriterWithHook returns a io.Writer that still writes to the actualWriter but also calls the hook function after every write. It is useful to use this function when you need to wait for a writer to complete writing inside a test.
func RandomID ¶
func RandomID() string
RandomID returns a unique, 64-character ID consisting of a-z, 0-9.
func TerminatePrompt ¶
Types ¶
type FakeCli ¶
FakeCli emulates the default DockerCli
func NewFakeCli ¶
NewFakeCli returns a fake for the command.Cli interface
func (*FakeCli) BuildKitEnabled ¶
BuildKitEnabled on the fake cli
func (*FakeCli) Client ¶
Client returns a docker API client
func (*FakeCli) ConfigFile ¶
func (c *FakeCli) ConfigFile() *configfile.ConfigFile
ConfigFile returns the cli configfile object (to get client configuration)
func (*FakeCli) ContextStore ¶
ContextStore returns the cli context store
func (*FakeCli) CurrentContext ¶
CurrentContext returns the cli context
func (*FakeCli) CurrentVersion ¶
CurrentVersion returns the API version used by FakeCli.
func (*FakeCli) DockerEndpoint ¶
DockerEndpoint returns the current DockerEndpoint
func (*FakeCli) Err ¶
Err returns the output stream (stderr) the cli should write on
func (*FakeCli) ErrBuffer ¶
ErrBuffer Buffer returns the stderr buffer
func (*FakeCli) In ¶
In returns the input stream the cli will use
func (*FakeCli) ManifestStore ¶
func (c *FakeCli) ManifestStore() manifeststore.Store
ManifestStore returns a fake store used for testing
func (*FakeCli) Out ¶
Out returns the output stream (stdout) the cli should write on
func (*FakeCli) OutBuffer ¶
OutBuffer returns the stdout buffer
func (*FakeCli) RegistryClient ¶
func (c *FakeCli) RegistryClient(bool) registryclient.RegistryClient
RegistryClient returns a fake client for testing
func (*FakeCli) ResetOutputBuffers ¶
func (c *FakeCli) ResetOutputBuffers()
ResetOutputBuffers resets the .OutBuffer() and.ErrBuffer() back to empty
func (*FakeCli) ServerInfo ¶
func (c *FakeCli) ServerInfo() command.ServerInfo
ServerInfo returns API server information for the server used by this client
func (*FakeCli) SetConfigFile ¶
func (c *FakeCli) SetConfigFile(configFile *configfile.ConfigFile)
SetConfigFile sets the "fake" config file
func (*FakeCli) SetContextStore ¶
SetContextStore sets the "fake" context store
func (*FakeCli) SetCurrentContext ¶
SetCurrentContext sets the "fake" current context
func (*FakeCli) SetDockerEndpoint ¶
SetDockerEndpoint sets the "fake" docker endpoint
func (*FakeCli) SetErr ¶
SetErr sets the stderr stream for the cli to the specified io.Writer
func (*FakeCli) SetIn ¶
SetIn sets the input of the cli to the specified ReadCloser
func (*FakeCli) SetManifestStore ¶
func (c *FakeCli) SetManifestStore(manifestStore manifeststore.Store)
SetManifestStore on the fake cli
func (*FakeCli) SetOut ¶
SetOut sets the stdout stream for the cli to the specified io.Writer
func (*FakeCli) SetRegistryClient ¶
func (c *FakeCli) SetRegistryClient(registryClient registryclient.RegistryClient)
SetRegistryClient on the fake cli
Source Files ¶
cli.go cmd.go doc.go randomid.go writer.go
Directories ¶
| Path | Synopsis |
|---|---|
| internal/test/builders | Package builders helps you create struct for your unit test while keeping them expressive. |
| internal/test/environment | |
| internal/test/network | |
| internal/test/output |
- Version
- v29.4.2+incompatible (latest)
- Published
- Apr 20, 2026
- Platform
- linux/amd64
- Imports
- 20 packages
- Last checked
- 9 hours ago –
Tools for package owners.