func MockExecHelper() {
	if os.Getenv("MOCK_EXEC_HELPER_PROCESS") != "1" {
		return
	}
	sleepstr := os.Getenv("MOCK_EXEC_SLEEP")
	if sleepstr != "" {
		dur, err := strconv.ParseInt(sleepstr, 10, 32)
		if err == nil && dur > 0 {
			time.Sleep(time.Duration(dur))
		}
	}
	out := os.Getenv("MOCK_EXEC_OUTPUT")
	if out != "" {
		fmt.Print(out)
	}
	var exitcode int64
	ecs := os.Getenv("MOCK_EXEC_EXIT_CODE")
	if ecs != "" {
		exitcode, _ = strconv.ParseInt(ecs, 10, 32)
	}
	os.Exit(int(exitcode))
}
MockExecHelper implements the logic for the helper process.

This function should be called from a test stub in your program used
exclusively for creating processes. The test stub shouldn't do anything
else.
package exec
import (
	"context"
	"fmt"
	"os"
	osexec "os/exec"
	"strconv"
	"time"
)
type MockEntry struct {
	ExitCode int
	Sleep time.Duration
	Output string
	Extra []string
}
func (me *MockEntry) GetEnvVars() []string {
	if me == nil {
		return []string{"MOCK_EXEC_EXIT_CODE=0"}
	}
	var s []string
	if me.ExitCode != 0 {
		s = append(s, fmt.Sprintf("MOCK_EXEC_EXIT_CODE=%d", me.ExitCode))
	}
	if me.Sleep > 0 {
		s = append(s, fmt.Sprintf("MOCK_EXEC_SLEEP=%d", me.Sleep))
	}
	s = append(s, "MOCK_EXEC_OUTPUT="+me.Output)
	if len(me.Extra) > 0 {
		s = append(s, me.Extra...)
	}
	return s
}
type MockBuilder struct {
	Index   int
	Entries []MockEntry
	Helper  string
}
func NewMockBuilder(helper string, entries ...MockEntry) *MockBuilder {
	return &MockBuilder{
		Helper:  helper,
		Entries: entries,
	}
}
func (mb *MockBuilder) Command(cmd string, args ...string) *osexec.Cmd {
	return mb.CommandContext(context.Background(), cmd, args...)
}
func (mb *MockBuilder) CommandContext(ctx context.Context, cmd string, args ...string) *osexec.Cmd {
	cs := []string{"-test.run=" + mb.Helper, "--", "cmd"}
	cs = append(cs, args...)
	command := osexec.CommandContext(ctx, os.Args[0], cs...)
	command.Env = []string{"MOCK_EXEC_HELPER_PROCESS=1"}
	var entry *MockEntry
	if mb.Index >= 0 && mb.Index < len(mb.Entries) {
		entry = &mb.Entries[mb.Index]
		mb.Index++
	}
	command.Env = append(command.Env, entry.GetEnvVars()...)
	return command
}
func (mb *MockBuilder) Reset(entries ...MockEntry) {
	mb.Index = 0
	mb.Entries = entries
}