cockroachdb / cockroachdb/cockroach
Rework test mocking logic within docs-issue-generation script to hide network resources behind an interface
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
See Ricky’s comment on here as a follow-up to the work on [#109788](https://github.com/cockroachdb/cockroach/pull/109788#discussion_r1323421891).
Quote for posterity:
Try an external resource like [this one](https://nathanleclaire.com/blog/2015/10/10/interfaces-and-composition-for-effective-unit-testing-in-golang/) or [this one](https://deliveroo.engineering/2019/05/17/testing-go-services-using-interfaces.html). It seems there are a ton of blog posts, if either of these don't make sense to you try Googling for them.
The short version is that this function would be "behind an interface" which might look like:
```
type jiraClient interface {
getJiraIssueFromGitHubIssue(org, repo string, issue int) (string, error)
}
type productionJiraClient struct {}
func (_ productionJiraClient) getJiraIssueFromGitHubIssue(org, repo string, issue int) (string, error) {
....
}
```
The "production" `jiraClient` will just call `getJiraIssueFromGitHubIssue` as it's defined here. Any function that wants to call `getJiraIssueFromGitHubIssue()` needs a `jiraClient` instance. For testing, use a special instance that does whatever "mock" functionality you need.
Jira issue: CRDB-31705
Contributor guide
Research direction
Start with the docs-issue-generation script and locate getJiraIssueFromGitHubIssue. Read the linked follow-up discussion and the referenced Go interface-testing examples, then identify the existing mock behavior and the production Jira call. Done means network access is behind a jiraClient interface and tests can provide a mock implementation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- tooling
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100