govmtest

package
v0.0.0-...-5d9f3d3 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Overview

Package govmtest is an API for running Go unit tests in the guest and collecting their results and test coverage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(t testing.TB, name string, mods ...Modifier)

Run compiles the tests added with WithPackageToTest and runs them in a QEMU VM configured by mods. It collects the test results and provides a pass/fail result of each individual test.

Run runs tests and benchmarks, but not fuzz tests.

The test environment in the VM is very minimal. If a test depends on other binaries or specific files to be present, they must be specified with additional initramfs commands via WithUimage.

All files and directories in the same directory as the test package will be made available to the test in the guest as well (e.g. testdata/ directories).

Coverage from the Go tests is collected if a coverage file name is specified via the VMTEST_GO_PROFILE env var, as well as integration test coverage if VMTEST_GOCOVERDIR is set.

  • TODO: specify test, bench, fuzz filter. Flags for fuzzing.

Types

type Modifier

type Modifier func(t testing.TB, o *Options) error

Modifier is a configurator for Options.

func WithGoTestTimeout

func WithGoTestTimeout(timeout time.Duration) Modifier

WithGoTestTimeout sets a timeout for individual Go test binaries.

func WithPackageToTest

func WithPackageToTest(pkgs ...string) Modifier

WithPackageToTest adds additional packages to the test.

func WithQEMUFn

func WithQEMUFn(fn ...qemu.Fn) Modifier

WithQEMUFn adds QEMU options.

func WithUimage

func WithUimage(mods ...uimage.Modifier) Modifier

WithUimage merges o with already appended initramfs build options.

type Options

type Options struct {
	Packages    []string
	QEMUOpts    []qemu.Fn
	Initramfs   []uimage.Modifier
	TestTimeout time.Duration
}

Options configures a Go test.

Jump to

Keyboard shortcuts

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