Documentation
¶
Index ¶
- Constants
- func MatchingLine(exp string, cmd *exec.Cmd) (func(context.Context, *exec.Cmd) error, error)
- func StopWithSignal(s os.Signal) func(*exec.Cmd) error
- type Cmd
- type Opt
- func WithArgsAppend(args ...string) Opt
- func WithArgsSet(args ...string) Opt
- func WithCommand(name string, args ...string) Opt
- func WithCommandFn(fn func() (*exec.Cmd, error)) Opt
- func WithDir(dir string) Opt
- func WithEnvAppend(env ...string) Opt
- func WithEnvSet(env ...string) Opt
- func WithExecCmd(cmd *exec.Cmd) Opt
- func WithGoCode(modulePath, mainPkg string) Opt
- func WithGoCover() Opt
- func WithGoCoverDir(dir string) Opt
- func WithReadyFn(fn func(context.Context, *exec.Cmd) error) Opt
- func WithReadyHTTP(url string) Opt
- func WithReadyTimeout(d time.Duration) Opt
- func WithStopFn(fn func(*exec.Cmd) error) Opt
- func WithWaitExit() Opt
- func WithWaitMatchingLine(exp string) Opt
Constants ¶
const ( ErrMissingCmd = strerr.Error("missing command") ErrStartFailed = strerr.Error("failed to start command") ErrReadyFailed = strerr.Error("failed to verify readiness") ErrStopFailed = strerr.Error("command didn't stop successfully") ErrOptApply = strerr.Error("failed apply Opt") ErrNoMatchingLine = strerr.Error("no matching line found") ErrNilCmdRegexp = strerr.Error("command has to be set before this option can be applied, check the order of options") ErrPreCmdFailed = strerr.Error("pre command failed") ErrBadRegexp = strerr.Error("bad regular expression for matching line") ErrOutputPipe = strerr.Error("failed to acquire output pipe for command") ErrBuildFailed = strerr.Error("failed to build go binary") ErrCreateCoverDir = strerr.Error("failed create coverage dir") )
Variables ¶
This section is empty.
Functions ¶
func MatchingLine ¶
MatchLine waits for the command to output a line that matches the given regular expression.
Types ¶
type Opt ¶
func WithArgsAppend ¶ added in v0.1.2
WithArgsAppend adds arguments to commands current argument list.
func WithArgsSet ¶ added in v0.1.2
WithArgsSet sets arguments for the command.
func WithCommand ¶
WithCommand creates a new command with the given name and arguments.
func WithCommandFn ¶ added in v0.2.0
WithCommandFn creates a new command using the given function. This is useful for lazy loading of the command and using arguments from other dependencies.
func WithEnvAppend ¶
WithEnvAppend adds environment variables to commands current env. By default the command inherits the environment of the current process and setting this option will override it.
func WithEnvSet ¶ added in v0.0.2
WithEnvSet sets environment variables for the command. By default the command inherits the environment of the current process and setting this option will override it.
func WithExecCmd ¶
WithExecCmd allows user to construct the command with custom exec.Cmd.
func WithGoCode ¶
WithGoCode builds the given Go projects and sets the main package as the command. By default the output binary is instrumented to collect coverage data Working directory for build command is set to modulePath which means that the mainPkg should be relative to it. Building the binary is done in a separate goroutine and the command is started only after the build is finished. Also building is done only once which allows to reuse the reusing the same Cmd instance without rebuilding the binary.
func WithGoCover ¶ added in v0.1.1
func WithGoCover() Opt
WithGoCover calls WithGoCoverDir with the os.Getenv("GOCOVERDIR") value if it's set. Otherwise it's a no-op.
func WithGoCoverDir ¶ added in v0.0.2
WithGoCoverDir creates the dir if it doesn't exist and appends the GOCOVERDIR env variable into the commands env.
func WithReadyFn ¶
WithReadyFn allows user to provide custom readiness function. Given fn should block until the command is ready.
func WithReadyHTTP ¶
WithReadyHTTP sets the ready function to wait for url to return 200 OK.
func WithReadyTimeout ¶
WithReadyTimeout overrides the default 30s timeout for the ready function.
func WithStopFn ¶
WithStopFn allows user to provide custom stop function.
func WithWaitExit ¶
func WithWaitExit() Opt
WithWaitExit sets the ready and stop functions so that ready waits for the command to exit successfully and stop returns nil immediately. This is useful for commands that exit on their own and don't need to be stopped manually.
func WithWaitMatchingLine ¶
WithWaitMatchingLine sets the ready function so that it waits for the command to output a line that matches the given regular expression.