Answer the question
In order to leave comments, you need to log in
How to test method calls on websocket.Conn from gorilla/websocket?
I'm trying to write a bus to push some events to the client. Decided to use gorilla/websocket . But I stopped at the most important place - actually receiving and sending messages. How can I test the fact that the connection is closed, for example? Okay, the Close method is in the standard interface, but how do you test that other methods have been called?
There is a strong feeling that these issues have already been resolved, but I could not find answers on my own.
Answer the question
In order to leave comments, you need to log in
To mock in unit tests, there is this: https://github.com/posener/wstest
There
is also an option to do integration / E2E
tests via
https://github.com/gavv/httpexpect the author's hands do not reach the review for 2 months).
There you can set tests both directly on the HTTP server with WS, and replace the client so that it immediately sticks to the handlers without raising a full-fledged HTTP server (just licked the idea with posener / wstest).
Both solutions are used by me on a real project without problems and quite successfully.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question