Practical fuzzing
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.
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.
How to do it...
These steps cover writing and running your application:
- From your terminal/console application, create the
chapter8/fuzz
directory and navigate to it. - Copy tests from https://github.com/agtorre/go-cookbook/tree/master/chapter8/fuzz or use this as an exercise to write some of your own code.
- Create a file...