Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to mock lib functions #454

Open
ihulsbus opened this issue Apr 28, 2022 · 2 comments
Open

How to mock lib functions #454

ihulsbus opened this issue Apr 28, 2022 · 2 comments
Labels
needs triage Ticket that needs triage (a proper look for classification)

Comments

@ihulsbus
Copy link

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:

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

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?

@andygrunwald andygrunwald added the needs triage Ticket that needs triage (a proper look for classification) label Aug 20, 2022
@andygrunwald
Copy link
Owner

Hey,

I am very sorry that this issue has been open for a long time with no final solution. We work on this project in our spare time, and sometimes, other priorities take over. This is the typical open source dilemma.

However, there is news: We are kicking off v2 of this library 🚀

To provide visibility, we created the Road to v2 Milestone and calling for your feedback in #489

The development will take some time; however, I hope you can benefit from the changes.
If you seek priority development for your issue + you like to sponsor it, please contact me.

What does this mean for my issue?

We will work on this issue indirectly.
This means that during the development phase, we aim to tackle it.
Maybe in a different way like it is currently handled.
Please understand that this will take a while because we are running this in our spare time.

Final words

Thanks for using this library.
If there is anything else you would like to tell us, let us know!

@ihulsbus
Copy link
Author

Hi, thanks for the response. no worries, life's busy and time is valuable.

In this case I think I made a conceptual mistake on my part with regards to testing and interface usage in Go. I'll need to double check but my gut feeling says this is at least partially solved. I'll get back on that once I find the time to dive back into this.

Cheers,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Ticket that needs triage (a proper look for classification)
Projects
None yet
Development

No branches or pull requests

2 participants