Last active
May 15, 2024 13:41
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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