Expose interfaces to public API to ease testing #295
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
I’ve been using NSQ in production for more than 3 years now and I sincerely want to thank you guys for the great work you’ve been doing.
This PR aims to expose newly created interfaces for
Conn
,Consumer
andProducer
, with the goal of making testing simpler. Please note that this PR does not break the current API in any way and that all the changes have been made with respect to the documentation.I know that this point was already discussed in #146 and I saw that PRs were welcome. So if it’s still the case and you think this kind of modification could be in respect with the roadmap, I would be more than glad to fix everything that needs to be in this PR. Otherwise, I can just close if. Just let me know if all this does not make any sense to you.
Please find below the definition of the main interfaces. More private ones are in the code. Obviously all the namings can be discussed. This was not the purpose of my contribution.
I also did my best to factorize code as much as possible in the logging part. Some code was duplicated across both the
consumer.go
,producer.go
andconn.go
, so I thought it might be interesting to gather everything into its own interface, and a default implementation.If this is something you might be interested in, the limiting part of this side is that the public API of
Conn
exposes a different prototype for bothSetLogger
andSetLoggerForLevel
, compared to the ones exposed byConsumer
andProducer
.Please note that this could be refactorized pretty easily, breaking the API but without any functional changes (e.g. using a default value for
format
). Thank you for taking the time to read and consider this PR