| 1 |
--- |
| 2 |
paths: |
| 3 |
- "**/*_test.go" |
| 4 |
--- |
| 5 |
|
| 6 |
# Testing conventions (go-openapi) |
| 7 |
|
| 8 |
## Running tests |
| 9 |
|
| 10 |
**Single module repos:** |
| 11 |
|
| 12 |
```sh |
| 13 |
go test ./... |
| 14 |
``` |
| 15 |
|
| 16 |
**Mono-repos (with `go.work`):** |
| 17 |
|
| 18 |
```sh |
| 19 |
# All modules |
| 20 |
go test work ./... |
| 21 |
|
| 22 |
# Single module |
| 23 |
go test ./conv/... |
| 24 |
``` |
| 25 |
|
| 26 |
Note: in mono-repos, plain `go test ./...` only tests the root module. |
| 27 |
The `work` pattern expands to all modules listed in `go.work`. |
| 28 |
|
| 29 |
CI runs tests on `{ubuntu, macos, windows} x {stable, oldstable}` with `-race` via `gotestsum`. |
| 30 |
|
| 31 |
## Fuzz tests |
| 32 |
|
| 33 |
```sh |
| 34 |
# List all fuzz targets |
| 35 |
go test -list Fuzz ./... |
| 36 |
|
| 37 |
# Run a specific target (go test -fuzz cannot span multiple packages) |
| 38 |
go test -fuzz=Fuzz -run='FuzzTargetName$' -fuzztime=1m30s ./package |
| 39 |
``` |
| 40 |
|
| 41 |
Fuzz corpus lives in `testdata/fuzz/` within each package. CI runs each fuzz target for 1m30s |
| 42 |
with a 5m minimize timeout. |
| 43 |
|
| 44 |
## Test framework |
| 45 |
|
| 46 |
`github.com/go-openapi/testify/v2` — a zero-dep fork of `stretchr/testify`. |
| 47 |
Because it's a fork, `testifylint` does not work. |