Testing websocket responses
Is this possible currently? I took a look at how the regular HTTP responses can be tested by feeding a response to the HttpRoutes object, but when feeding the same response I get a 501 response in status code.
I tried seeing the source for how tests are doing it and whether Request definition has some clues, but no clues jumped out at me. 😛
Any suggestions would be appreciated by me and perhaps by other people hopefully stumbling upon this later by googling.
The 501 is the default onNonWebSocketRequest in the WebSocketBuilder. The response should have a WebSocketContext attribute with key org.http4s.server.websocketKey. The WebSocketContext contains the WebSocket, that you can interact with via send and receive.
There's no helper I know of that digs through this, or implements client logic like responding to pings with pongs or doing the close handshake. A helper, or at least an example, for this would be great.
The response should have a WebSocketContext attribute
Should the "response" have been "request" here or no?
No, response. When you post to a web socket route, you get back a response with an attribute that represents the server's view of the web socket. You can then interact with the send and receive on that web socket to act as the client.