www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How would I go about unittesting a vibe.d app?

reply rinfz <cherez mailbox.org> writes:
For example, I am trying to test a route. Within the unittest I 
setup the server locally (note: is it possible to start the 
server once for all unit tests?), then call listenHTTP. After the 
listen call I make a client request to localhost with requestHTTP 
and I get the following error:

WARNING: HTTPClientResponse not fully processed before being 
finalized

The code for reference:

unittest {
// imports...
auto listener = setupServer(); // makes the listenHTTP call
scope(exit) listener.stopListening();

requestHTTP(
   environment["HOST"] ~ "/register",
   (scope req) {
     req.method = HTTPMethod.POST;
     req.writeFormBody(["foo": "bar"]);
   },
   (scope res) {
     assert (res.statusCode == 200);
   },
);
}

Note: I am running tests using dub if that is relevant.
Oct 30 2020
parent rinfz <cherez mailbox.org> writes:
On Friday, 30 October 2020 at 13:26:59 UTC, rinfz wrote:
 ...
Seems I have got something working using the fluent-asserts-vibe package.
Oct 30 2020