4f3a1e6f7d
* [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>
1.5 KiB
1.5 KiB
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:
-
- 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
)
- Set environment variables must be unset (use
-
Able to run in parallel
- All package level
Test*
functions should start withci.Parallel
- Always use dynamic scratch dirs, files
- Always get ports from helpers (
TestServer
,TestClient
,TestAgent
,freeport.Get
)
- All package level
-
Log control
- Logging must go through the
testing.T
(usehelper/testlog.HCLogger
) - Avoid excessive logging in test cases - prefer failure messages
- Annotate failures with
must.Sprint\f
post-scripts
- Annotate failures with
- Logging must go through the
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 Github Action works.