ellzey/libevhtp — pull request #129 by tjeezy (2014-07-02 17:54:51+00:00)
Title: first attempt at improving unit testing outside of libevhtp

Hey Mark,

Wanted to get your feedback on this patch. The idea is to improve unit testing in the source that uses libevhtp. For example, with this patch (or one similar to it -- I've been working on a few commits behind HEAD of develop), we are able to "mock" an `evhtp_request_t`, pass it into a callback and then inspect it on the other side. All this really does is add checks before utilizing `req->conn` because in a mocked request, the connection and associated structs are not *valid*.

For example,

```
evhtp_request_t *req = NULL;

// by default, request has no URI
req = evhtp_request_new(NULL, NULL);
route(req, params);
ASSERT("request should 404 without a URI", EVHTP_RES_NOTFOUND == req->status);
evhtp_request_free(req);

evhtp_path_t path;
evhtp_uri_t uri;
uri.path = &path;

path.full = "/v0/";
req = evhtp_request_new(NULL, NULL);
FREE(req->uri);
req->uri = &uri;
route(req, params);
ASSERT("request should 404 with bad handler version", EVHTP_RES_NOTFOUND == req->status);
req->uri = NULL;
evhtp_request_free(req);
```