[GH-ISSUE #282] [FEATURE REQUEST] Use interfaces #110

Closed
opened 2026-03-02 05:18:45 +03:00 by kerem · 3 comments
Owner

Originally created by @mrsufgi on GitHub (Jun 21, 2021).
Original GitHub issue: https://github.com/hibiken/asynq/issues/282

Originally assigned to: @hibiken on GitHub.

Is your feature request related to a problem? Please describe.
Im using asynq in several projects and I find myself create partial interfaces for asynq.Client (type) so I can mock on my unit tests. It's tedius, partial and redunant and could be helpful to have "Official" interfaces returned from NewClient function

further reference on how do you mock uninterfaced dependencies
https://dev.to/jonfriesen/mocking-dependencies-in-go-1h4d

Describe the solution you'd like
client.go -> callings NewClient returns AsynqClient interface instead of Client type (struct)

Thanks for this awesome package! <3

Originally created by @mrsufgi on GitHub (Jun 21, 2021). Original GitHub issue: https://github.com/hibiken/asynq/issues/282 Originally assigned to: @hibiken on GitHub. **Is your feature request related to a problem? Please describe.** Im using asynq in several projects and I find myself create partial interfaces for asynq.Client (type) so I can mock on my unit tests. It's tedius, partial and redunant and could be helpful to have "Official" interfaces returned from NewClient function further reference on how do you mock uninterfaced dependencies https://dev.to/jonfriesen/mocking-dependencies-in-go-1h4d **Describe the solution you'd like** client.go -> callings `NewClient` returns `AsynqClient` interface instead of Client type (struct) Thanks for this awesome package! <3
kerem 2026-03-02 05:18:45 +03:00
Author
Owner

@crossworth commented on GitHub (Jul 10, 2021):

Hi, I don't think we improve the library by doing this. The idiomatic way is for the consumer to define the interface, the reference that you pointed show that as well, I know that is a bit tedius doing that for every project, but you could use a interface generator tool or create a wrapper around the AsyncClient.

For more references see the links below:

There is a video where William Kennedy talks exactly about this scenario, but I couldn't find it.

Anyway, that's my opinion.

<!-- gh-comment-id:877641186 --> @crossworth commented on GitHub (Jul 10, 2021): Hi, I don't think we improve the library by doing this. The idiomatic way is for the consumer to define the interface, the reference that you pointed show that as well, I know that is a bit tedius doing that for every project, but you could use a interface generator tool or create a wrapper around the AsyncClient. For more references see the links below: - https://github.com/golang/go/wiki/CodeReviewComments#interfaces - https://www.ardanlabs.com/blog/2016/10/avoid-interface-pollution.html - https://rakyll.org/interface-pollution/ There is a video where William Kennedy talks exactly about this scenario, but I couldn't find it. Anyway, that's my opinion.
Author
Owner

@hibiken commented on GitHub (Jul 10, 2021):

@mrsufgi Thank you for opening this issue! While I can related to the pain of defining interface in every project, I agree with @crossworth in that we shouldn't make this API change.

These feedback on APIs are very useful, so if you have more please don't hesitate to open an issue!

<!-- gh-comment-id:877662648 --> @hibiken commented on GitHub (Jul 10, 2021): @mrsufgi Thank you for opening this issue! While I can related to the pain of defining interface in every project, I agree with @crossworth in that we shouldn't make this API change. These feedback on APIs are very useful, so if you have more please don't hesitate to open an issue!
Author
Owner

@mrsufgi commented on GitHub (Jul 11, 2021):

Thank you for your answers! I agree, if interfaces are only meant for testing, I can use something like
https://github.com/vburenin/ifacemaker

To easily generate them from structs :)
🥳

<!-- gh-comment-id:877748584 --> @mrsufgi commented on GitHub (Jul 11, 2021): Thank you for your answers! I agree, if interfaces are only meant for testing, I can use something like https://github.com/vburenin/ifacemaker To easily generate them from structs :) 🥳
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/asynq#110
No description provided.