Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save prestonvasquez/8038c092b803edd2ed1a85ecffd8e979 to your computer and use it in GitHub Desktop.
Save prestonvasquez/8038c092b803edd2ed1a85ecffd8e979 to your computer and use it in GitHub Desktop.
Fuzz Testing Example
func Foo(i int, s string) (string, error) {
if i%7 == 0 && s == "hello" {
return s, fmt.Errorf("error")
}
return fmt.Sprintf("%d: %s", i, s), nil
}
func FuzzFoo(f *testing.F) {
f.Add(5, "hello") // Seed corpus addition
f.Fuzz(func(t *testing.T, i int, s string) {
out, err := Foo(i, s)
if err != nil && out != "" {
t.Errorf("Foo(%v, %v) returned error %v", i, s, err)
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment