Test Jsonnet Files¶
This project uses Testonnet.
This method is simple and straight-forward.
This approach is perfect for writing unit tests that asserts the output of a particular method.
There is also support for negative tests, where you can assert that a particular method throws an error.
Location of Test Files¶
Jsonnet test files must stay in the same directory and have the same name as the jsonnet file being tested but ending in
_test.jsonnet. Some examples:
services/stages.libsonnet->services/stages_test.jsonnetlibsonnet/toolinglinks/sentry.libsonnet->libsonnet/toolinglinks/sentry_test.jsonnet
In addition negative test files must end with _test_negative_<description>.jsonnet. Some examples:
services/stages.libsonnet->services/stages_test_negative_no-stages.jsonnetlibsonnet/toolinglinks/sentry.libsonnet->libsonnet/toolinglinks/sentry_test_negative_no-sentry.jsonnet
Negative test files only support one assertion per file.
How to Run Tests?¶
Run the full Jsonnet test suite in your local environment with mise run tests:jsonnet. To run an individual file,
provide it as the first argument.
Note
Verify that you have all the jsonnet dependencies downloaded before attempting to run the tests, you can
automatically download the necessary dependencies by running mise init.