Refactor: Extract RabbitMQ management client & provide fakes #89
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.
This came from my looking into #88. Our only tests that touched the controller also used a real RabbitMQ, so it was not possible to control the responses from the RabbitMQ API in these tests, and force the API to respond with a 401.
This extracts all of the rabbithole client logic into a factory, which creates an object providing all of the rabbithole methods that we use in our controllers. This also adds counterfeiter methods to create fakes for all of these methods, allowing us to write more comprehensive integration tests at the per-controller level.
In the actual binary, we use a factory to generate a real rabbithole client. In the tests, we can now create our own mock factory which creates a fake RabbitMQ management client, which can return whatever we choose in the tests.
I will use this framework to address #88 by writing a test to return an error response from rabbithole, and triggering the panic hit in that error.
Additional considerations
This means we will have to add to the interface and regenerate the fake code whenever we use a new rabbithole method. We can always add a make target for the autogen side of this if needs be.