testutil

package
v0.0.0-...-522126a Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2019 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package testutil contains utility functions for runsc tests.

Index

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 Copy

func Copy(src, dst string) error

Copy copies file from src to dst.

func FindFile

func FindFile(path string) (string, error)

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 IsStatic

func IsStatic(filename string) (bool, error)

IsStatic returns true iff the given file is a static binary.

func KillCommand

func KillCommand(cmd *exec.Cmd) error

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

func NewSpecWithArgs(args ...string) *specs.Spec

NewSpecWithArgs creates a simple spec with the given args suitable for use in tests.

func Poll

func Poll(cb func() error, timeout time.Duration) error

Poll is a shorthand function to poll for something with given timeout.

func RandomName

func RandomName(prefix string) string

RandomName create a name with a 6 digit random number appended to it.

func SetupBundleDir

func SetupBundleDir(spec *specs.Spec) (bundleDir string, err error)

SetupBundleDir creates a bundle dir and writes the spec to config.json.

func SetupContainer

func SetupContainer(spec *specs.Spec, conf *boot.Config) (rootDir, bundleDir string, err error)

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

func SetupRootDir() (string, error)

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

func TestBoundsForShard(numTests int) (int, int, error)

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

func TestConfig() *boot.Config

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

func WaitForHTTP(port int, timeout time.Duration) error

WaitForHTTP tries GET requests on a port until the call succeeds or timeout.

func WaitUntilRead

func WaitUntilRead(r io.Reader, want string, split bufio.SplitFunc, timeout time.Duration) error

WaitUntilRead reads from the given reader until the wanted string is found or until timeout.

func WriteTmpFile

func WriteTmpFile(pattern, text string) (string, error)

WriteTmpFile writes text to a temporary file, closes the file, and returns the name of the file.

Types

type Reaper

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

Reaper reaps child processes.

func (*Reaper) Start

func (r *Reaper) Start()

Start starts reaping child processes.

func (*Reaper) Stop

func (r *Reaper) Stop()

Stop stops reaping child processes.

Jump to

Keyboard shortcuts

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