Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

add support for generics for source mode #640

Merged
merged 15 commits into from
May 12, 2022
Merged

add support for generics for source mode #640

merged 15 commits into from
May 12, 2022

Conversation

codyoss
Copy link
Member

@codyoss codyoss commented May 3, 2022

Updates: #621

@codyoss
Copy link
Member Author

codyoss commented May 3, 2022

Needs a bunch of tests and things still, but should not take too much more to get this working fully

@codyoss
Copy link
Member Author

codyoss commented May 3, 2022

Also, still need to look into reflect support.

@omichels
Copy link

omichels commented May 5, 2022

i have tried to use this fork but found out that the generated mocks are simply missing the type information

@codyoss
Copy link
Member Author

codyoss commented May 5, 2022

@omichels It is still a WIP progress ATM, but getting closer. I have not committed everything yet either. I will ping on the linked issue when I think the PR is in a good state and see if anyone is still having issues. Thanks for being an early tester though!

@codyoss codyoss changed the title add support for generics add support for generics for source mode May 5, 2022
@codyoss
Copy link
Member Author

codyoss commented May 6, 2022

@omichels Would you mind trying again to see if you are still seeing issues?

@omichels
Copy link

omichels commented May 9, 2022

@omichels Would you mind trying again to see if you are still seeing issues?

Looks fine now. Thank you so much.

This is our use case:

"our" API, which we want to mock:

type ResourceGroupClient interface {
  NewListPager(options *armresources.ResourceGroupsClientListOptions) *runtime.Pager[armresources.ResourceGroupsClientListResponse]
}

Azure sdk:

type Pager[T any] struct {
	current   *T
	processor PageProcessor[T]
	firstPage bool
}

type PageProcessor[T any] struct {
	More func(T) bool
	Fetcher func(context.Context, *T) (T, error)
}

func (client *ResourceGroupsClient) NewListPager(options *ResourceGroupsClientListOptions) *runtime.Pager[ResourceGroupsClientListResponse] {
...
}

@steve-gray
Copy link

Hey @codyoss - Keen to give this a spin as we're being burned with some code changes - in essence we can't regenerate mocks on some services now as a common package we have uses generics internally.

When I try to install with the CLI, it bombs out due to the go.mod paths not matching - there a way to force the install?

go install github.com/codyoss/mock/mockgen@891f4736814577b05df08811fd90798a66bdde38


go: github.com/codyoss/mock/mockgen@891f4736814577b05df08811fd90798a66bdde38: github.com/codyoss/[email protected]: parsing go.mod:
        module declares its path as: github.com/golang/mock
                but was required as: github.com/codyoss/mock

@codyoss
Copy link
Member Author

codyoss commented May 11, 2022

@steve-gray I don' think you can go install from a fork, but I could be wrong. You should be able to check out this code locally though and run go install ./... to build from source. Let me know how that works for you

As a side not I do plan on trying to get at least this PR merged sometime this week. But there are still likely a couple of edge cases and reflect mode support before I officially cut a release.

@steve-gray
Copy link

Seems to quietly do its thing without erroring, tests are running again. Cheers @codyoss - I'll keep an eye out for the full release 🚀

@codyoss codyoss marked this pull request as ready for review May 12, 2022 03:01
@codyoss codyoss merged commit 73266f9 into golang:main May 12, 2022
@codyoss codyoss deleted the generics branch May 12, 2022 03:06
@opannapo
Copy link

Thanks a lot suhu

@steve-gray
Copy link

@codyoss is there going to be a release cut at some point with this change in it to simplify the install story for people?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants