Skip to content

Instantly share code, notes, and snippets.

@getvictor
Last active May 15, 2024 13:41
Show Gist options
  • Save getvictor/24baadcc9cf08e7d7a6028ad54ff2aba to your computer and use it in GitHub Desktop.
Save getvictor/24baadcc9cf08e7d7a6028ad54ff2aba to your computer and use it in GitHub Desktop.
Sample fuzz test for exploring fuzz testing functionality. Full article at https://victoronsoftware.com/posts/fuzz-testing-with-go/
package main
import (
"testing"
)
/// Sample fuzz test for exploring fuzz testing functionality.
func FuzzSample(f *testing.F) {
testcases := []struct {
Num uint8
Name string
}{{Num: 8, Name: "name"}}
for _, tc := range testcases {
f.Add(tc.Num, tc.Name)
}
f.Add(uint8(0), "")
f.Fuzz(func(t *testing.T, orig uint8, name string) {
if orig == 1 && len(name) > 5 && name[1] == 'a' {
t.Error("Found 0")
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment