# Go Standards - Fuzz Testing
> **Module:** testing-fuzz.md | **Sections:** 5 | **Parent:** [index.md](index.md)
This module covers native Go fuzz testing patterns. Fuzz tests automatically generate random inputs to find bugs that manual testing misses.
> **Gate Reference:** This module is loaded by `ring:qa-analyst` at Gate 4 (Fuzz Testing).
---
## Table of Contents
| # | [Section Name](#anchor-link) | Description |
|---|------------------------------|-------------|
| 1 | [What Is Fuzz Testing](#what-is-fuzz-testing) | Purpose and when to use |
| 2 | [Fuzz Function Pattern](#fuzz-function-pattern-mandatory) | Go 1.18+ native fuzz syntax |
| 3 | [Seed Corpus](#seed-corpus-mandatory) | Initial test cases for fuzzer |
| 4 | [Input Types](#input-types) | Supported fuzz input types |
| 5 | [Fuzz Test Quality Gate](#fuzz-test-quality-gate-mandatory) | Checklist before completion |
**Meta-sections:** [Output Format (Gate 4 - Fuzz Testing)](#output-format-gate-4---fuzz-testing), [Anti-Rationalization Table](#anti-rationalization-table-fuzz-testing)
---
## What Is Fuzz Testing
Fuzz testing automatically generates **millions of random inputs** to find bugs that manual testing misses.
### Key Differences from Unit Tests
| Aspect | Unit Test | Fuzz Test |
|--------|-----------|-----------|
| **Who defines inputs?** | You (manual) | Fuzzer (automatic) |
| **Number of cases** | 5-20 cases | Millions |
| **What it finds** | Known bugs | Unknown bugs |
| **Speed** | Fast | Varies (can run for hours) |
| **Where to use** | All code | Input validation, parsing |
### When to Use Fuzz Testing
| Use Fuzz For | Don't Use Fuzz For |
|--------------|-------------------|
| Input validation functions | Business logic with mocks |
| Parsers (JSON, XML, custom) | Database operations |
| Serialization/deserialization | External API calls |
| String manipulation | Slow operations |
| Security-sensitive code | UI components |
### What Fuzz Tests Verify
```go
// PROPERTY: No panic, no 5xx errors
// The fuzzer tries to crash your code with random inputs
result, err := ValidateInput(randomInput)
// If no panic occurs, the test passes
```
---
## Fuzz Function Pattern (MANDATORY)
**HARD GATE:** All fuzz tests MUST use Go 1.18+ native fuzz syntax (`*testing.F`).
### Required Pattern
```go
func FuzzCreateOrganization_LegalName(f *testing.F) {
// Step 1: Seed corpus with edge cases
f.Add("Acme, Inc.") // valid
f.Add("") // empty
f.Add("日本語") // unicode
f.Add("") // XSS attempt
f.Add(strings.Repeat("x", 1000)) // long string
// Step 2: Define fuzz function
f.Fuzz(func(t *testing.T, name string) {
// Step 3: Bound input to prevent resource exhaustion
if len(name) > 512 {
name = name[:512]
}
// Step 4: Call function under test
// PROPERTY: No panic, returns error gracefully
result, err := ValidateOrganizationName(name)
// Step 5: Verify properties (not specific values)
if err == nil {
assert.NotEmpty(t, result)
}
// No panic = test passes
})
}
```
### Function Naming Convention
| Pattern | Example |
|---------|---------|
| `Fuzz{Subject}_{Field}` | `FuzzCreateOrganization_LegalName` |
| `Fuzz{Function}_{Input}` | `FuzzParseJSON_Payload` |
| `Fuzz{Validator}_{Field}` | `FuzzValidateEmail_Address` |
### File Naming
```text
*_test.go (unit test file, not integration)
Examples:
- validator_test.go
- parser_test.go
- serializer_test.go
```
**Note:** Fuzz tests are unit-level tests. They run without containers and must be fast.
---
## Seed Corpus (MANDATORY)
**HARD GATE:** All fuzz tests MUST include seed corpus with edge cases. Empty seed corpus is FORBIDDEN.
### Seed Corpus Categories
| Category | Examples | Purpose |
|----------|----------|---------|
| Valid inputs | `"Acme, Inc."`, `"user@example.com"` | Ensure valid inputs work |
| Empty/nil | `""`, `nil` | Edge case handling |
| Boundary | `strings.Repeat("x", MaxLength)` | Length limits |
| Unicode | `"日本語"`, `"🎉"`, `"α β γ"` | Encoding handling |
| Invalid formats | `"{ invalid json }"` | Error handling |
| Security payloads | `"