mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
* [no ci] use json for grouping packages for testing * [no ci] able to get packages in group * [no ci] able to run groups of tests * [no ci] more * [no ci] try disable circle unit tests * ci: use actions/checkout@v3 * ci: rename to quick * ci: need make dev in mods cache step * ci: make compile step depend on checks step * ci: bump consul and vault versions * ci: need make dev for group tests * ci: update ci unit testing docs * docs: spell plumbing correctly Co-authored-by: Tim Gross <tgross@hashicorp.com> Co-authored-by: Tim Gross <tgross@hashicorp.com>
41 lines
1.5 KiB
Markdown
41 lines
1.5 KiB
Markdown
# 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:
|
|
|
|
- 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
|
|
|
|
- Undo any changes to the environment
|
|
- Set environment variables must be unset (use `t.Setenv`)
|
|
- Scratch files/dirs must be removed (use `t.TempDir`)
|
|
- Consumed ports must be freed (e.g. `TestServer.Cleanup`, `freeport.Return`)
|
|
|
|
- Able to run in parallel
|
|
- All package level `Test*` functions should start with `ci.Parallel`
|
|
- Always use dynamic scratch dirs, files
|
|
- Always get ports from helpers (`TestServer`, `TestClient`, `TestAgent`, `freeport.Get`)
|
|
|
|
- Log control
|
|
- Logging must go through the `testing.T` (use `helper/testlog.HCLogger`)
|
|
- Avoid excessive logging in test cases - prefer failure messages
|
|
- Annotate failures with `must.Sprint\f` post-scripts
|
|
|
|
## 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.
|
|
|
|
|
|
# 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.
|