Register a stub for an external command. Pattern is a regular expression, output is the standard output from a command. Pass callbacks to inspect raw arguments that the command was invoked with.
(pattern string, exitStatus int, output string, callbacks ...CommandCallback)
| 72 | // Register a stub for an external command. Pattern is a regular expression, output is the standard output |
| 73 | // from a command. Pass callbacks to inspect raw arguments that the command was invoked with. |
| 74 | func (cs *CommandStubber) Register(pattern string, exitStatus int, output string, callbacks ...CommandCallback) { |
| 75 | if len(pattern) < 1 { |
| 76 | panic("cannot use empty regexp pattern") |
| 77 | } |
| 78 | if strings.HasPrefix(pattern, "git") { |
| 79 | pattern = addGitAuthentication(pattern) |
| 80 | } |
| 81 | cs.stubs = append(cs.stubs, &commandStub{ |
| 82 | pattern: regexp.MustCompile(pattern), |
| 83 | exitStatus: exitStatus, |
| 84 | stdout: output, |
| 85 | callbacks: callbacks, |
| 86 | }) |
| 87 | } |
| 88 | |
| 89 | func (cs *CommandStubber) find(args []string) *commandStub { |
| 90 | line := strings.Join(args, " ") |