go-nsq icon indicating copy to clipboard operation
go-nsq copied to clipboard

consumer/producer: add interfaces

Open bkeroackdsc opened this issue 9 years ago • 6 comments

To facilitate testing, I've found myself abstracting out the go-nsq API so I can swap in mock implementations.

nsq.Producer/nsq.Consumer should be interfaces so that users don't have to create their own abstraction layer.

bkeroackdsc avatar Jun 02 '15 20:06 bkeroackdsc

@bkeroackdsc While i use something similar (see gist) I'm not convinced that this belongs in the go-nsq library (or that it would be easy to do so w/o breaking api compatibility promises).

Perhaps we could add a nsqtesting subpackage?

thoughts @mreiferson ?

jehiah avatar Jun 02 '15 20:06 jehiah

Yea, we couldn't return interfaces in the constructors without breaking compatibility, however we could introduce new interfaces that could provide a mechanism for speccing that out and being used in end-user tests?

mreiferson avatar Jun 02 '15 22:06 mreiferson

@mreiferson That seems like a reasonable compromise.

bkeroackdsc avatar Jun 03 '15 18:06 bkeroackdsc

@mreiferson Are those new interfaces introduced already? I have to test a method that uses DeferredPublish..

sefasenturk95 avatar Mar 09 '18 09:03 sefasenturk95

No, PRs welcome!

mreiferson avatar Mar 09 '18 17:03 mreiferson

Guys, I think you don't need to make those interfaces if you want. But, could you make a public API for change the connections instance in producer and consumer? I think the other way (alternative) to test this nsq is to implement custom net memory listener with a pipe. So, that we could implement a custom mock for the nsq.

fairyhunter13 avatar Mar 10 '19 23:03 fairyhunter13