Add SSE support to MockClient#573
Conversation
There was a problem hiding this comment.
So, I think we want to do a few things here:
-
Its not obvious from the outside that
Unrest::sseends up doing a GET on the URL, so I expect the MockClient to have a method that explicitly is for SSE. It's fine if internally it sets up the GET, but from the outside the MockClient should have the same convenience as the real client. -
Users should not be expected to understand the raw formal of SSE streams. They should not expect to set delimitation or other formatting things about SSE. So the
.thenReturnsshould accept an object or list of objects that define objects and the bodies.
Something like (and this is sudo code). In this example "EventStream" is an object that the user can feed more events to and it will stream out. I would look at how WebSockets are done. I would expect something similar.:
client.expectSSE("http://events")
.thenReturn(EventStream.of(
new Event("greeting", "hello"),
new Event("greeting", "world")
));
Summary
Adds basic Server-Sent Events support to
MockClient.Motivation
MockClientpreviously did not support SSE requests. The SSE methods returnednullor an empty stream, soUnirest.sse(...).connect(...)could not be tested with mock expectations.Fixes #570.
Changes
GETrequests for expectation matching.expect(...).thenReturn(...)API.text/event-streamresponse bodies intoEventobjects.Testing
mvn -pl unirest-modules-mocks -am test