Right now the aerogear-app-metrics service has plenty of unit tests and some basic integration tests for the dao (database) package. Those integration tests might be useful for this ticket. They can be found here:
https://github.com/aerogear/aerogear-app-metrics/tree/master/pkg/dao
Notice the build tags at the top of the tests in the dao library. {{// +build integration}} These ensure the integration tests are not run unless we explicitly pass an extra flag. You can see how this works in the {{make test-integrate}} and {{make test-integrate-cover}} commands in the [Makefile|https://github.com/aerogear/aerogear-app-metrics/blob/master/makefile#L53-L64]
This style should also be used with this ticket. There is already This will allow the tests to run in CI without any additional work.
The outcome of this task is to create tests that spin up the server and test the behaviour of the metrics service in full against a postgres instance. The goal is to cover the "happy scenarios" and all of the expected error scenarios.
The following PRs (already merged) had manual verification steps which outline a good number of potential request scenarios and the expected behaviour.
* https://github.com/aerogear/aerogear-app-metrics/pull/33 * https://github.com/aerogear/aerogear-app-metrics/pull/31 * https://github.com/aerogear/aerogear-app-metrics/pull/28 * https://github.com/aerogear/aerogear-app-metrics/pull/18
The tests should probably do the following:
* Create a new package in the pkg folder called 'test' * Add the test file(s) in this folder * Make sure to use the {{// +build integration}} flag at the top of the test file(s). * Initialize the app business logic and router in the same way that cmd/metrics-api/metrics-api.go does it. * Insert the router into a httptest.Server using the built in [httptest library|https://golang.org/pkg/net/http/httptest] * Create a matrix of client payloads and expected responses to run a suite of tests against the server * Potentially implement some mechanism to actually verify the records in the database?
There doesn't need to be any clever stuff to start the database. The database will be available in CI and the tests should automatically run as long as the {{// +build integration}} was included. |
|