Testing
Table of contents
tl;dr: make before_commit will run most of the checks by magic, VERBOSE=true make before_commit
will do the same but print more information about what it’s doing
The following tests can be run to test your code in insights-results-aggregator.
Detailed information about each type of test is included in the corresponding subsection:
- Unit tests: checks behavior of all units in source code (methods, functions)
- REST API Tests: test the real REST API of locally deployed application with database initialized with test data only
- Integration tests: the integration tests for
insights-results-aggregatorservice - Metrics tests: test whether Prometheus metrics are exposed as expected
Unit tests
Set of unit tests checks all units of source code. Additionally the code coverage is computed and
displayed. Code coverage is stored in a file coverage.out and can be checked by a script named
check_coverage.sh.
To run unit tests use the following command:
make test
If you have postgres running on port from ./config-devel.toml file it will also run tests against
it
All integration tests
make integration_tests
Only REST API tests
Set of tests to check REST API of locally deployed application with database initialized with test data only.
To run REST API tests use the following command:
make rest_api_tests
By default all logs from the application aren’t shown, if you want to see them, run:
./test.sh rest_api --verbose
Coverage reports
To make a coverage report you need to start ./make-coverage.sh tool with one of these arguments:
unit-postgresunit tests with postgres database(don’t forget to startdocker-compose upwith the DB)restREST API tests fromtest.shfileintegrationAny external tests, for example from iqe-ccx-plugin. Only this option requires you to run tests manually and stop the script byCtrl+Cwhen they are done
For example:
./make-coverage.sh unit-postgres will generate a report file coverage.out
which you can investigate by either of those commands:
go tool cover -func=coverage.outgo tool cover -html=coverage.outif your system supports it, this command will open a browser with a nice colored report
OpenAPI checks
Content of file openapi.json can be checked by using:
make openapi-check
It is also possible to use online checker that is available on https://apitools.dev/swagger-parser/online/