timonv/travis-cli — pull request #3 by timonv (2012-11-21 21:16:32+00:00)
Title: Make tests work without running the actual git commands

Infant go doesn't really provide any features for easily stubbing methods. Travis build now fails because it's not in a git repo.

The git_helpers has a cmdBranch and cmdShowOrigin that execute a git command. They (or rather their response) need to be stubbed.

The conundrum is that there doesn't seem to be a single proper way to deal with this. Options are (afaik):

1. Use a similar pattern as to the adapters (Factory an object; query it) and inject the cmd method into the struct. Like:

```go
type GitBranch struct {
Name string
cmdBranch func() (string,error)
}

func NewGitBranch() GitBranch {
return GitBranch{Name: "", cmdBranch: cmdBranch}
}
```

2. Have a value that, if present, precedes the cmd call:

```go
type GitBranch struct {
Name string
StubbedCmd string
}

func (gb GitBranch) cmdBranch() (string, error) {
if gb.StubbedCmd != nil {
return gb.StubbedCmd, nil
} else {
...
}
}
```

3. There are several external libraries and suggestions. One real ugly one is overriding the actual cmd (in the shell) or using gomock which rewrites code.

Now I prefer the first solution. However, it strongly enforces a certain pattern to be used (Factory -> Composite Type -> func property) which is fine, but shouldn't be mandatory.

Any takes?