command

package
v0.7.22 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAllContainerIDs

func GetAllContainerIDs(o *option.Option) []string

GetAllContainerIDs returns all container IDs.

func GetAllImageIDs

func GetAllImageIDs(o *option.Option) []string

GetAllImageIDs returns all image IDs.

func GetAllImageNames

func GetAllImageNames(o *option.Option) []string

GetAllImageNames returns all image names.

func GetAllNetworkNames

func GetAllNetworkNames(o *option.Option) []string

GetAllNetworkNames returns all network names.

func GetAllVolumeNames

func GetAllVolumeNames(o *option.Option) []string

GetAllVolumeNames returns all volume names.

func RemoveAll

func RemoveAll(o *option.Option)

RemoveAll removes all containers and images in the testing environment specified by o.

func RemoveContainers

func RemoveContainers(o *option.Option)

RemoveContainers removes all containers in the testing environment specified by o.

func RemoveImages

func RemoveImages(o *option.Option)

RemoveImages removes all container images in the testing environment specified by o.

func RemoveNetworks

func RemoveNetworks(o *option.Option)

RemoveNetworks removes all networks in the testing environment specified by o. TODO: use "network prune" after upgrading nerdctl to v0.23.

func RemoveVolumes

func RemoveVolumes(o *option.Option)

RemoveVolumes removes all unused local volumes in the testing environment specified by o.

func Run

func Run(o *option.Option, args ...string) *gexec.Session

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

func RunWithoutSuccessfulExit(o *option.Option, args ...string) *gexec.Session

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

func RunWithoutWait(o *option.Option, args ...string) *gexec.Session

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 Stderr added in v0.3.0

func Stderr(o *option.Option, args ...string) []byte

Stderr invokes Run and returns the stderr.

func StderrAsLines added in v0.3.0

func StderrAsLines(o *option.Option, args ...string) []string

StderrAsLines invokes Run and returns the stderr as lines.

func StderrStr added in v0.3.0

func StderrStr(o *option.Option, args ...string) string

StderrStr invokes Run and returns the output in string format.

func Stdout added in v0.3.0

func Stdout(o *option.Option, args ...string) []byte

Stdout invokes Run and returns the stdout.

func StdoutAsLines added in v0.3.0

func StdoutAsLines(o *option.Option, args ...string) []string

StdoutAsLines invokes Run and returns the stdout as lines.

func StdoutStr

func StdoutStr(o *option.Option, args ...string) string

StdoutStr invokes Run and returns the output in string format.

Types

type Command

type Command struct {
	// contains filtered or unexported fields
}

Command represents a to-be-executed shell command.

func New

func New(opt *option.Option, args ...string) *Command

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

func (c *Command) Run() *gexec.Session

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) WithStdin

func (c *Command) WithStdin(stdin io.Reader) *Command

WithStdin specifies the input reader for gexec.Start.

func (*Command) WithStdout

func (c *Command) WithStdout(stdout io.Writer) *Command

WithStdout specifies the output writer for gexec.Start.

func (*Command) WithTimeout

func (c *Command) WithTimeout(timeout time.Duration) *Command

WithTimeout updates the timeout for the session.

func (*Command) WithTimeoutInSeconds

func (c *Command) WithTimeoutInSeconds(timeout time.Duration) *Command

WithTimeoutInSeconds updates the timeout (in seconds) for the session.

func (*Command) WithoutCheckingExitCode

func (c *Command) WithoutCheckingExitCode() *Command

WithoutCheckingExitCode disables exit code checking after the session ends.

func (*Command) WithoutSuccessfulExit

func (c *Command) WithoutSuccessfulExit() *Command

WithoutSuccessfulExit ensures that the exit code of the command is not 0.

func (*Command) WithoutWait

func (c *Command) WithoutWait() *Command

WithoutWait disables waiting for a session to finish.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL