Documentation ¶
Overview ¶
Package command invokes external commands.
It is designed in a way that the users of the `tests` package can also utilize this package when writing their own tests.
Index ¶
- func GetAllContainerIDs(o *option.Option) []string
- func GetAllImageIDs(o *option.Option) []string
- func GetAllImageNames(o *option.Option) []string
- func GetAllNetworkNames(o *option.Option) []string
- func GetAllVolumeNames(o *option.Option) []string
- func RemoveAll(o *option.Option)
- func RemoveContainers(o *option.Option)
- func RemoveImages(o *option.Option)
- func RemoveNetworks(o *option.Option)
- func RemoveVolumes(o *option.Option)
- func Run(o *option.Option, args ...string) *gexec.Session
- func RunWithoutSuccessfulExit(o *option.Option, args ...string) *gexec.Session
- func RunWithoutWait(o *option.Option, args ...string) *gexec.Session
- func SetLocalRegistryContainerID(id string)
- func SetLocalRegistryImageID(id string)
- func SetLocalRegistryImageName(name string)
- func Stderr(o *option.Option, args ...string) []byte
- func StderrAsLines(o *option.Option, args ...string) []string
- func StderrStr(o *option.Option, args ...string) string
- func Stdout(o *option.Option, args ...string) []byte
- func StdoutAsLines(o *option.Option, args ...string) []string
- func StdoutStr(o *option.Option, args ...string) string
- type Command
- func (c *Command) Run() *gexec.Session
- func (c *Command) WithStdin(stdin io.Reader) *Command
- func (c *Command) WithStdout(stdout io.Writer) *Command
- func (c *Command) WithTimeout(timeout time.Duration) *Command
- func (c *Command) WithTimeoutInSeconds(timeout time.Duration) *Command
- func (c *Command) WithoutCheckingExitCode() *Command
- func (c *Command) WithoutSuccessfulExit() *Command
- func (c *Command) WithoutWait() *Command
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetAllContainerIDs ¶
GetAllContainerIDs returns all container IDs.
func GetAllImageIDs ¶
GetAllImageIDs returns all image IDs.
func GetAllImageNames ¶
GetAllImageNames returns all image names.
func GetAllNetworkNames ¶
GetAllNetworkNames returns all network names.
func GetAllVolumeNames ¶
GetAllVolumeNames returns all volume names.
func RemoveAll ¶
RemoveAll removes all containers and images in the testing environment specified by o.
func RemoveContainers ¶
RemoveContainers removes all containers in the testing environment specified by o.
func RemoveImages ¶
RemoveImages removes all container images in the testing environment specified by o.
func RemoveNetworks ¶
RemoveNetworks removes all networks in the testing environment specified by o. TODO: use "network prune" after upgrading nerdctl to v0.23.
func RemoveVolumes ¶
RemoveVolumes removes all unused local volumes in the testing environment specified by o.
func Run ¶
Run starts a session, waits for it to finish, ensures the exit code to be 0, and returns the ended session to be used for assertions.
func RunWithoutSuccessfulExit ¶
RunWithoutSuccessfulExit starts a session, waits for it to finish, ensures the exit code not to be 0, and returns the ended session to be used for assertions.
func RunWithoutWait ¶
RunWithoutWait starts a session without waiting for it to finish.
func SetLocalRegistryContainerID ¶
func SetLocalRegistryContainerID(id string)
SetLocalRegistryContainerID sets the ID for the local registry. Usually you don't need to invoke this function yourself. For more details, see tests.SetupLocalRegistry.
func SetLocalRegistryImageID ¶
func SetLocalRegistryImageID(id string)
SetLocalRegistryImageID sets the ID for local registry image. Usually you don't need to invoke this function yourself. For more details, see tests.SetupLocalRegistry.
func SetLocalRegistryImageName ¶
func SetLocalRegistryImageName(name string)
SetLocalRegistryImageName sets the local registry image name. Usually you don't need to invoke this function yourself. For more details, see tests.SetupLocalRegistry.
func StderrAsLines ¶ added in v0.3.0
StderrAsLines invokes Run and returns the stderr as lines.
func StdoutAsLines ¶ added in v0.3.0
StdoutAsLines invokes Run and returns the stdout as lines.
Types ¶
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
Command represents a to-be-executed shell command.
func New ¶
New creates a command with the default configuration. Invoke the WithXXX methods to configure it. After it's configured, invoke Run to run the command.
Also check the RunXXX and StdXXX wrapper functions in this package for simple use cases. As a rule of thumb, please don't create a wrapper function for a use case that involves more than one thing. For example,
command.RunWithoutSuccessfulExit(o, arg).Err.Contents()
may be more readable than
command.RunWithoutSuccessfulExitAndReturnStderr(o, arg)
func (*Command) Run ¶
Run starts a session and waits for it to finish. It's behavior can be modified by using other Command methods. It returns the ended session for further assertions.
func (*Command) WithStdout ¶
WithStdout specifies the output writer for gexec.Start.
func (*Command) WithTimeout ¶
WithTimeout updates the timeout for the session.
func (*Command) WithTimeoutInSeconds ¶
WithTimeoutInSeconds updates the timeout (in seconds) for the session.
func (*Command) WithoutCheckingExitCode ¶
WithoutCheckingExitCode disables exit code checking after the session ends.
func (*Command) WithoutSuccessfulExit ¶
WithoutSuccessfulExit ensures that the exit code of the command is not 0.
func (*Command) WithoutWait ¶
WithoutWait disables waiting for a session to finish.