andygrunwald / andygrunwald/go-jira
How to mock lib functions
- Dominant language
- Go
- Stars
- 1.6k
- Forks
- 500
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
I'm trying to mock one of the functions in this library so that I can perform tests without actually talking to a Jira instance.
I've not been able to find documentation for this anywhere in the lib. To give an example, let's take the following function:
```go
func jiraFindAll() ([]*m.IssueProject, error) {
var projects []*m.IssueProject
data, _, err := jiraClient.Project.GetList()
if err != nil {
return projects, err
}
for _, project := range *data {
projects = append(projects, &m.IssueProject{
ID: project.ID,
Key: project.Key,
Name: project.Name,
})
}
return projects, nil
}
```
If I want to write tests for this function I would like to replace the `jiraClient.Project.GetList()` function to give a mocked response instead of contacting an actual Jira instance.
I've tried to override the API function like
```go
jira.Project.GetList = func () (*jira.ProjectList, *jira.Response, error) {
return mockedResponse, nil, nil
}
```
But that seems to be unsupported here. How could I achieve this?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.