livepeer / livepeer/go-livepeer
Refactor CLI HTTP requests to improve testability
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 586
- Forks
- 226
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 19
Description
**Is your feature request related to a problem? Please describe.**
Currently in the CLI wizard code with use the functions `httpPostWithParams` and `httpGet` in a way that does not allow us to fake them out for testing.
It would be helpful to refactor them out into an interface that `wizard` would be constructed with, such that these functions could be easily faked.
**Describe the solution you'd like**
The solution could look something like:
```
type Server interface {
httpPostWithParams(url string, val url.Values) string
httpGet(url string) string
}
```
and when we construct wizard it would look like:
```
s := &server {
endpoint: fmt.Sprintf("http://%v:%v/status", c.String("host"), c.String("http")),
httpPort: c.String("http"),
host: c.String("host"),
}
w := &wizard {
server: s,
in: bufio.NewReader(os.Stdin),
}
```
**Describe alternatives you've considered**
We could make these functions package variables that can be overridden in tests, but I find the interface approach to be a bit cleaner.
**Additional context**
None.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the CLI wizard code and the httpPostWithParams, httpGet, and wizard entry points. Trace how wizard is constructed, then define the injectable server boundary described in the issue and add fakes in the relevant tests. Done means wizard HTTP calls can be replaced for testing without changing its CLI behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli, testing-qa
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100