Mocking the connect function of nats #1665
-
Any one having idea on how we can mock the nats.Connect function I tried in many ways but still its not working,
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
There is no mock available. We recommend running an actual nats-server for tests. It is really lightweight and especially easy in Go, where you can run it embedded into your tests. |
Beta Was this translation helpful? Give feedback.
-
Running the NATS server in tests works well for us: https://github.com/simpleiot/simpleiot/blob/master/client/rule_test.go The NATS Go test code is full of examples of this as well. |
Beta Was this translation helpful? Give feedback.
There is no mock available.
Considering how rich is NATS API, it would be really hard, if not impossible, to mock everything in a reliable way, or a way that helps more than harms.
We recommend running an actual nats-server for tests. It is really lightweight and especially easy in Go, where you can run it embedded into your tests.