Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dispatch ¶
func Dispatch()
Dispatch can be used to launch multiple subprocesses as part of a go test. If you want to throw up in your mouth a little, then read the implementation. Don't worry, this is apparently a "blessed" hack for doing this sort of thing.
You always want to call testprocess.Dispatch() at the beginning of your TestMain function since confusing things will happen if you call it later on or have complex logic surrounding calls to it. For each subprocess you want, use testprocess.Make to create an *exec.Cmd variable and save it in a global (it must be global for this to work). The resulting commands that are returned can be started/stopped at any point later in your test, e.g.:
func TestMain(m *testing.M) { testprocess.Dispatch() os.Exit(m.Run()) } var fooCmd = testprocess.Make(func() { doFoo(); }) var barCmd = testprocess.Make(func() { doBar(); }) var bazcmd = testprocess.Make(func() { doBaz(); }) func TestSomething(t *testing.T) { ... err := fooCmd.Run() ... }
It is permissible, but not required, to call flag.Parse before calling testprocess.Dispatch. If flag.Parse has not been called, then testprocess.Dispatch will call it.
func Make ¶
Make returns an *exec.Cmd that will execute the supplied function in a subprocess. For this to work, testprocess.Dispatch must be invoked by the TestMain of any test suite using this, and the call to Make must be *before* the call to testprocess.Dispatch; possibly from a global variable initializer, e.g.:
var myCmd = testprocess.Make(func() { doSomething(); })
Types ¶
This section is empty.