Documentation
¶
Overview ¶
Package maintest makes it easy to create end-to-end tests for executables with support for code coverage, debugging, and more.
maintest must be used within the `main` package within the `TestMain` function.
Index ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Exe ¶
type Exe struct { Path string // Path is the full path to the executable file useful for passing to exec.Command CoverageDir string // Directory where coverage results will temporarily go after every invocation // contains filtered or unexported fields }
Exe is an instrumented executable that can be easily run in integration tests.
To execute, use Command(args...).
After all commands have finished, Finish must be called for the coverage data to be written.
func Build ¶
Build builds the named executable using the local module (meant to be run in TestMain). The test executable will be called exeName and placed in a temporary directory. The executable can be run
func (*Exe) Command ¶
Command returns Cmd ready to be run that will invoke the built test executable and output the results to the shared coverage directory.
func (*Exe) Finish ¶
Finish will merge all the coverage from the previous executions and write the output to -coverprofile. This func uses the `go tool covdata` command with textfmt for backwards compatibility with existing tools, e.g. `go tool covdata textfmt -i b.CoverageDir -o '-coverprofile'`. -coverprofile is parsed from os.Args.
type Option ¶
type Option func(e *Exe)
func Debug ¶
Debug builds the executable with debug symbols enabled and optionally starts dlv for debugging.
This is useful if you want to attach and debug your executable in your integration tests while they run. Using dlv exec (see https://github.com/go-delve/delve/blob/master/Documentation/usage/dlv_exec.md) allows a test to be "paused" and attached to interactively, which makes it possible to debug the actual executable rather than the test fixture which is much less interesting. dlvArgs will be passed to the run like `dlv exec [dlvArgs...] [exeAndFlags...]`
func DebugFlag ¶
DebugFlag will add a flag to the command line that can be specified to enable debug mode
func Package ¶
Package will cause `go build` to run on a different package than the current directory. The package must have an executable (`package main`).
func WriteCoverage ¶
WriteCoverage redirects the coverage from -coverprofile to override path.