From golang-workflow
Go fuzz testing patterns using built-in fuzzing support (Go 1.18+)
npx claudepluginhub jamesprial/prial-plugins --plugin golang-workflowThis skill uses the workspace's default tool permissions.
Go 1.18+ includes native fuzz testing. Use fuzzing when functions handle external input, parse data, or validate untrusted content.
Implements idiomatic Go testing patterns including table-driven tests, subtests, benchmarks, fuzzing, and coverage. Guides TDD workflow for new functions, existing code, and performance.
Provides Go testing patterns with TDD: table-driven tests, subtests, benchmarks, fuzzing, and coverage for reliable, idiomatic tests.
Guides coverage-guided fuzz testing for Rust projects using cargo-fuzz: init, fuzz targets with libFuzzer/Arbitrary, corpus management, and CI integration.
Share bugs, ideas, or general feedback.
Go 1.18+ includes native fuzz testing. Use fuzzing when functions handle external input, parse data, or validate untrusted content.
func Fuzz_Parse(f *testing.F) {
// Seed corpus: known interesting inputs
f.Add([]byte(`{"valid": true}`))
f.Add([]byte(`{}`))
f.Add([]byte(``))
f.Add([]byte(`null`))
f.Fuzz(func(t *testing.T, data []byte) {
// Invariant: Parse must never panic
result, err := Parse(data)
if err != nil {
return // errors are acceptable
}
// If parse succeeds, result must be usable
if result == nil {
t.Error("Parse returned nil result without error")
}
})
}
Every fuzz test must check at least one invariant:
| Invariant | Description | Example |
|---|---|---|
| No panics | Function never panics on any input | Parser, validator |
| Round-trip | Encode(Decode(x)) == x | Serialization |
| Idempotent | F(F(x)) == F(x) | Normalization |
| Bounded output | Output length/size within limits | Compression |
| Error or valid | Returns error OR valid result, never garbage | Any function |
# Run for 30 seconds
go test -fuzz=Fuzz_Parse -fuzztime=30s ./...
# Run until failure
go test -fuzz=Fuzz_Parse ./...
# Run specific fuzz test
go test -fuzz=^Fuzz_Parse$ -fuzztime=10s ./pkg/parser/
// WRONG: No invariant checked
f.Fuzz(func(t *testing.T, data []byte) {
Parse(data) // just calling it isn't enough
})
// CORRECT: Check meaningful invariant
f.Fuzz(func(t *testing.T, data []byte) {
result, err := Parse(data)
if err == nil && result.Valid() == false {
t.Error("Parse returned invalid result without error")
}
})