Lapin Sandbox
lswith opened this issue · 6 comments
I've started to work a lot with elixir and I've noticed the best frameworks are the ones that provide some sort of sandbox for a developer to substitute in when they write test cases. Currently, to test against lapin, I need to have an actual rabbitmq host running. It would be nice to have an in-memory sandbox that I could substitute in to test against.
The scope would look something like this:
- doesn't require an amqp server
- allows the control of messages through test harnesses (I can determine when I wish to send a message)
- allows messages to be prepopulated on the queue
I've just added Travis CI integration to the master branch. Travis automatically runs tests and provides RabbitMQ in the test sandbox, so tests are automatically executed against a real broker with no setup overhead on our part.
AMQP allows you to declare configuration as part of the protocol, setting up exchanges and queues. Lapin does this automatically by default. I think this is more practical than setting up a custom test environment for now.
Ah I think the sandbox is more for people integrating with your library rather than testing internally.
Ok, so I guess some kind of mock simulating the broker interaction. I guess this is interesting. Do you have a pointer to an existing library which does this for tests for reference?
I wrote one on this open source repo here: https://github.com/lswith/analytics-elixir
The sandbox can be swapped out for the actual Genserver. This allows our tests to make sure that the lib is being called without actually making the http requests.
See also https://github.com/jcabotc/hare/blob/master/lib/hare/adapter/sandbox.ex for a concrete rabbitmq example.
I haven't used this rabbitmq lib directly though (I used the previous attempt at Rabbitmq by the same author, jcabotc/channels
).
Thanks guys, I'll look into the examples. As my time is currently limited I'm going to be prioritizing other features though.
Also, the current travis setup already allows for easy instantiation of a real rabbitmq broker in the sandbox and at least on mac running rabbit locally is a no brainer.