Documentation
¶
Overview ¶
Package spawn makes it easy to end-to-end test Go servers. The main idea is that you spin up your server in your TestMain(), use it throughout your tests and shut it down at the end.
Refer to the examples directory for usage information.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cmd ¶
Cmd wraps exec.Cmd and represents a binary being prepared or run.
In the typical end-to-end testing scenario, Cmd will end up running two times:
- from TestMain when the test suite is first executed. At this point it will spawn the already-compiled test binary (itself) again and...
- from the spawned binary, inside TestMain again. But this time it will intercept TestMain and will execute main() instead (i.e. the actual program)
func New ¶
New returns a Cmd that will either execute the passed in main() function, or the parent binary with the given arguments. The program's main() function should be passed as f.
func (*Cmd) Start ¶
Start starts c until it terminates or ctx is cancelled. It does not wait for it to complete. When ctx is cancelled a SIGINT is sent to c.
The Wait method will return the exit code and release associated resources once the command exits.
func (*Cmd) Wait ¶
Wait waits for the command to exit and waits for any copying to stdin or copying from stdout or stderr to complete.
The command must have been started by Start.
The returned error is nil if the command runs, has no problems copying stdin, stdout, and stderr, exits with a zero exit status and any signals to the command were delivered successfully.
Wait releases any resources associated with the command.