andygrunwald / andygrunwald/go-jira
How to mock lib functions
- 主要语言
- Go
- 星标
- 1.6k
- 派生
- 500
- PR 合并指标
- 30 天内没有已合并 PR
描述
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?
贡献指南
这个仓库没有索引到贡献指南
评估
这个 Issue 还没有评估数据。