2022-03-15 12:42:43 +00:00
|
|
|
# Writing Tests
|
|
|
|
|
|
|
|
The Nomad repository strives to maintain comprehensive unit test coverage. Any new
|
|
|
|
features, bug fixes, or refactoring should include additional or updated test cases
|
|
|
|
demonstrating correct functionality.
|
|
|
|
|
|
|
|
Each unit test should meet a few criteria:
|
|
|
|
|
2022-10-27 14:02:58 +00:00
|
|
|
- Use [github.com/shoenig/test](https://github.com/shoenig/test)
|
|
|
|
- Prefer using `must.*`` functions
|
|
|
|
- Use `test.*`` functions when cleanup must happen, etc
|
|
|
|
- Feel free to refactor testify tests; but consider separate commits / PRs
|
2022-03-15 12:42:43 +00:00
|
|
|
|
|
|
|
- Undo any changes to the environment
|
2022-10-27 14:02:58 +00:00
|
|
|
- Set environment variables must be unset (use `t.Setenv`)
|
|
|
|
- Scratch files/dirs must be removed (use `t.TempDir`)
|
2022-03-15 12:42:43 +00:00
|
|
|
|
|
|
|
- Able to run in parallel
|
2022-10-27 14:02:58 +00:00
|
|
|
- All package level `Test*` functions should start with `ci.Parallel`
|
2022-03-15 12:42:43 +00:00
|
|
|
- Always use dynamic scratch dirs, files
|
2023-01-03 17:25:20 +00:00
|
|
|
- Always get ports via `ci.PortAllocator.Grab()`
|
2022-03-15 12:42:43 +00:00
|
|
|
|
|
|
|
- Log control
|
2022-10-27 14:02:58 +00:00
|
|
|
- Logging must go through the `testing.T` (use `helper/testlog.HCLogger`)
|
2022-05-16 15:12:54 +00:00
|
|
|
- Avoid excessive logging in test cases - prefer failure messages
|
2022-10-27 14:02:58 +00:00
|
|
|
- Annotate failures with `must.Sprint\f` post-scripts
|
2022-05-16 15:12:54 +00:00
|
|
|
|
|
|
|
## API tests
|
|
|
|
|
|
|
|
Testing in the `api` package requires an already-built Nomad
|
|
|
|
binary. If you're writing `api` tests, you'll need to build a Nomad
|
|
|
|
binary (ex. with `make dev`) that includes any changes your API
|
|
|
|
exercises.
|
2022-10-27 14:02:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
# CI Plumbing
|
|
|
|
|
|
|
|
See [ci/README.md] for details on how the [Core CI Tests](https://github.com/hashicorp/nomad/actions/workflows/test-core.yaml)
|
|
|
|
Github Action works.
|