go-nsq
go-nsq copied to clipboard
consumer/producer: add interfaces
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 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 ?
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 That seems like a reasonable compromise.
@mreiferson Are those new interfaces introduced already? I have to test a method that uses DeferredPublish..
No, PRs welcome!
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.