Commit Graph

11 Commits

Author SHA1 Message Date
Taylor Blau
ec6137aacf api/lock_api: use id, force as explicit arguments 2016-05-27 15:45:02 -06:00
Taylor Blau
f5578f3de8 api: add Force option to unlock requests 2016-05-27 15:42:04 -06:00
Taylor Blau
44ac3a9b3a api{client,lifecycle}: use config.Endpoint to resolve root 2016-05-25 13:31:12 -06:00
Taylor Blau
4bf693ed64 api: http.Method{Get,Post} does not exist in Go <1.6 2016-05-24 10:50:58 -06:00
Taylor Blau
8887924fff api/{lock,schema} validate LockList against schema 2016-05-24 09:27:17 -06:00
Taylor Blau
d352a3fc48 api/schema: rename AssertSchema to AssertRequestSchema 2016-05-24 09:27:16 -06:00
Taylor Blau
1654834630 api/lock: implement LockService.Search 2016-05-24 09:27:16 -06:00
Taylor Blau
32c557a497 api/{lock,schema}: add lock API schemas, test against the Lock API 2016-05-24 09:27:16 -06:00
Taylor Blau
f7fc82387f api/schema: remove MethodTestCase in favor of AssertSchema()
MethodTestCase had lots of problems, most caused by a good degree of ambiguity
in what we were actually testing.

AssertSchema(), on the other hand, simplifies this problem greatly by correctly
identifying the responsibilities of an *api.RequestSchema. An
*api.RequestSchema is responsible for one thing, and one thing only: to provide
a template for requests to be made against the API, completely regardless of
protocol or implementation.

Most notably, these responsibilities do not include:
 - Preforming an HTTP request, or
 - reading the response of an http request

So MethodTestCase gets simplified to a simple assert.Equal(). We expect to get
some *api.RequestSchema out, and we expect it to have certain parameters. Now,
all of the API's Service tests are rather simple: create a schema, compare,
rinse and repeat.

The only thing left to do is test the schema of the request and response
payload. This is what I had tried to do with the original MethodTestCase
implementation, but the way the system is desinged, trying to accomplish this
involves integrating with too many unrelated parts. To address this, I plan to
introduce a JSON Schema implementation that compares generated request/reponse
payloads with their ideal types.
2016-05-24 09:27:16 -06:00
Taylor Blau
7b73f83bdc api/schema: teach MethodTestCase how to serialize a repsonse
One of the things I'd mentioned that I disliked about the initial
implementation of MethodTestCase was that it required you to type out three
things (see previous commit). Of particular importance are items (2) and (3),
the expected and actual response, one a Go type, the other a JSON string.

This commit reduces that typing by 1/2. Since all we were doing was typing the
same data in two different formats, the only thing that we were really testing
was the encoding/json package. That is redundant, and a bad boundary to include
during testing. Therefore, instead of having to type out the JSON-encoded
string, this commit delegates that responsibility into the MethodTestCase's
server, and just uses a `json.Encoder` to do the work.

Sweet!
2016-05-24 09:27:15 -06:00
Taylor Blau
c282983235 api/schema: initial take on MethodTestCase
The initial thought here is to introduce a MethodTestCase type that
encapsulates the behavior of testing a single method in a particular given
service.

To do so, a httptest.Server is created and the schema is turned into a request
which is fired at that server. Thet MethodTestCase, of course, knows how to
respond to different requests, and the behavior of those responses is tested.

What I dislike is that we have to write three things which are mostly the same
to test any endpoint in any case on the API:
  1) a request type (Go struct)
  2) an expected response type (Go type)
  3) the actual response (a mutltline Go string, which is really just JSON)

This seems redundant, so I may explore other options for implementing this sort
of thing in the future.
2016-05-24 09:27:15 -06:00