Add fuzz tests to ci#156
Conversation
Signed-off-by: Derek McGowan <derek@mcg.dev>
There was a problem hiding this comment.
Pull request overview
This PR updates the GitHub Actions CI workflow to run Go unit tests and Go fuzz tests as part of pull request/merge-queue validation.
Changes:
- Add a new “Unit Tests” CI job running
go test -raceacross all non-integration packages. - Add a new “Fuzz Tests” CI job that discovers
Fuzz*targets and runs each for a fixed fuzzing duration.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| grep -r --include='*_test.go' -l '^func Fuzz' . | while read -r file; do | ||
| pkg=$(dirname "$file") | ||
| grep -o '^func Fuzz[A-Za-z0-9_]*' "$file" | sed 's/^func //' | while read -r target; do | ||
| echo "=== Fuzzing ${target} in ${pkg} ===" | ||
| go test "${pkg}" -fuzz="^${target}$" -fuzztime=60s | ||
| done | ||
| done |
There was a problem hiding this comment.
The fuzz step will fail the job when no fuzz targets exist. In GitHub Actions’ default bash settings (errexit + pipefail), grep -r ... -l '^func Fuzz' exits 1 when it finds no matches, which currently happens in this repo (no func Fuzz... found). Make this step a no-op when there are no fuzz tests (e.g., capture matches and exit 0 when empty) or add the fuzz tests in the same PR.
| # Find all packages containing fuzz tests and run each target. | ||
| # go test -fuzz only accepts one package at a time and one | ||
| # matching fuzz target, so we discover and iterate. | ||
| grep -r --include='*_test.go' -l '^func Fuzz' . | while read -r file; do |
There was a problem hiding this comment.
grep -r ... . will recursively scan everything in the checkout (including .git/ and any vendored/generated directories), which can be slow and may produce false positives. Prefer restricting discovery to tracked Go test files (e.g., via git ls-files '*_test.go') and/or explicitly excluding .git, vendor, and _output from the search.
| grep -r --include='*_test.go' -l '^func Fuzz' . | while read -r file; do | |
| git ls-files '*_test.go' | while read -r file; do | |
| grep -q '^func Fuzz' "$file" || continue |
Run fuzz tests as a part of CI