Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DockerTestResolver ¶
DockerTestResolver is a resolver meant for use with the containerized system tests. The logic here is extremely simple: if USE_HOSTFS is set, return that for the resolver
Types ¶
type DockerTestRunner ¶
type DockerTestRunner struct { Runner *testing.T // Privileged is equivalent to the `--privileged` flag passed to `docker run`. Sets elevated permissions. Privileged bool // Sets the filepath passed to `go test` Basepath string // Testname will run a given test if set Testname string // Container name passed to `docker run`. Container string // RunAsUser will run the container as a non-root user if set to the given username // equivalent to `--user=USER` RunAsUser string // CgroupNSMode sets the cgroup namespace for the container. Newer versions of docker // will default to a private namespace. Unexpected namespace values have resulted in bugs. CgroupNSMode container.CgroupnsMode // Verbose enables debug-level logging Verbose bool // FatalLogMessages will fail the test if a given string appears in the log output for the test. // Useful for turning non-fatal errors into fatal errors. // These are just passed to strings.Contains(). I.e. []string{"Non-fatal error"} FatalLogMessages []string // MonitorPID will tell tests to specifically check the correctness of process-level monitoring for this PID MonitorPID int // CreateHostProcess: this will start a process with the following args outside of the container, // and use the integration tests to monitor it. // Useful as "monitor random running processes" as a test heuristic tends to be flaky. // This will overrite MonitorPID, so only set either this or MonitorPID. CreateHostProcess *exec.Cmd }
DockerTestRunner is a simple test framework for running a given go test inside a container. In order for this framework to work fully, tests running under this framework must use systemtests.DockerTestResolver() to fetch the hostfs, and also set debug-level logging via `logp`.
func (*DockerTestRunner) CreateAndRunPermissionMatrix ¶
func (tr *DockerTestRunner) CreateAndRunPermissionMatrix(ctx context.Context, cgroupNSValues []container.CgroupnsMode, privilegedValues []bool, runAsUserValues []string)
CreateAndRunPermissionMatrix is a helper that runs RunTestsOnDocker() across a range of possible docker settings. If a given array value is supplied in the method arguments, it will be used to override the value in DockerTestRunner, and run the test for as many times as there are supplied values. For example, if privilegedValues=[true, false], then RunTestsOnDocker() will be run twice, setting the privileged flag differently for each run. if an array argument is empty, the default value set in the DockerTestRunner instance will be used.
func (*DockerTestRunner) RunTestsOnDocker ¶
func (tr *DockerTestRunner) RunTestsOnDocker(ctx context.Context)
RunTestsOnDocker runs a provided test, or all the package tests (as in `go test ./...`) inside a docker container with the host's root FS mounted as /hostfs. This framework relies on the tests using DockerTestResolver(). If docker returns !0 or if there's a matching string entry from FatalLogMessages in stdout/stderr, this will fail the test