Documentation ¶
Overview ¶
Package testutil contains utility functions for runsc tests.
Index ¶
- func ConfigureExePath() error
- func Copy(src, dst string) error
- func FindFile(path string) (string, error)
- func IsCheckpointSupported() bool
- func IsStatic(filename string) (bool, error)
- func KillCommand(cmd *exec.Cmd) error
- func NewSpecWithArgs(args ...string) *specs.Spec
- func Poll(cb func() error, timeout time.Duration) error
- func RandomName(prefix string) string
- func SetupBundleDir(spec *specs.Spec) (bundleDir string, err error)
- func SetupContainer(spec *specs.Spec, conf *boot.Config) (rootDir, bundleDir string, err error)
- func SetupRootDir() (string, error)
- func StartReaper() func()
- func TestBoundsForShard(numTests int) (int, int, error)
- func TestConfig() *boot.Config
- func TmpDir() string
- func UniqueContainerID() string
- func WaitForHTTP(port int, timeout time.Duration) error
- func WaitUntilRead(r io.Reader, want string, split bufio.SplitFunc, timeout time.Duration) error
- func WriteTmpFile(pattern, text string) (string, error)
- type Reaper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConfigureExePath ¶
func ConfigureExePath() error
ConfigureExePath configures the executable for runsc in the test environment.
func FindFile ¶
FindFile searchs for a file inside the test run environment. It returns the full path to the file. It fails if none or more than one file is found.
func IsCheckpointSupported ¶
func IsCheckpointSupported() bool
IsCheckpointSupported returns the relevant command line flag.
func KillCommand ¶
KillCommand kills the process running cmd unless it hasn't been started. It returns an error if it cannot kill the process unless the reason is that the process has already exited.
func NewSpecWithArgs ¶
NewSpecWithArgs creates a simple spec with the given args suitable for use in tests.
func RandomName ¶
RandomName create a name with a 6 digit random number appended to it.
func SetupBundleDir ¶
SetupBundleDir creates a bundle dir and writes the spec to config.json.
func SetupContainer ¶
SetupContainer creates a bundle and root dir for the container, generates a test config, and writes the spec to config.json in the bundle dir.
func SetupRootDir ¶
SetupRootDir creates a root directory for containers.
func StartReaper ¶
func StartReaper() func()
StartReaper is a helper that starts a new Reaper and returns a function to stop it.
func TestBoundsForShard ¶
TestBoundsForShard calculates the beginning and end indices for the test based on the TEST_SHARD_INDEX and TEST_TOTAL_SHARDS environment vars. The returned ints are the beginning (inclusive) and end (exclusive) of the subslice corresponding to the shard. If either of the env vars are not present, then the function will return bounds that include all tests. If there are more shards than there are tests, then the returned list may be empty.
func TestConfig ¶
TestConfig returns the default configuration to use in tests. Note that 'RootDir' must be set by caller if required.
func TmpDir ¶
func TmpDir() string
TmpDir returns the absolute path to a writable directory that can be used as scratch by the test.
func UniqueContainerID ¶
func UniqueContainerID() string
UniqueContainerID generates a unique container id for each test.
The container id is used to create an abstract unix domain socket, which must be unique. While the container forbids creating two containers with the same name, sometimes between test runs the socket does not get cleaned up quickly enough, causing container creation to fail.
func WaitForHTTP ¶
WaitForHTTP tries GET requests on a port until the call succeeds or timeout.
func WaitUntilRead ¶
WaitUntilRead reads from the given reader until the wanted string is found or until timeout.
func WriteTmpFile ¶
WriteTmpFile writes text to a temporary file, closes the file, and returns the name of the file.