This recipe will explore fuzzing and how it can be used to help validate functions. In the Currency conversions and float64 considerations recipe from Chapter 3, Data Conversion and Composition, we created a function that takes decimal US currency as a string and returns an int64 version representing cents. We'll modify that function and demonstrate finding a panic with fuzzing.
Practical fuzzing
Getting ready
Configure your environment according to these steps:
- Refer to the Getting ready section of the Mocking using the standard library recipe of this chapter.
- Run the go get github.com/dvyukov/go-fuzz/go-fuzz command.
- Run the go get github.com/dvyukov/go-fuzz/go-fuzz-build command.