livepeer / livepeer/go-livepeer

Refactor CLI HTTP requests to improve testability

Open
#673 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area: cli status: icebox type: refactor type: tech debt
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.