4 gofuzz is a library for populating go objects with random values.
6 [![GoDoc](https://godoc.org/github.com/google/gofuzz?status.png)](https://godoc.org/github.com/google/gofuzz)
7 [![Travis](https://travis-ci.org/google/gofuzz.svg?branch=master)](https://travis-ci.org/google/gofuzz)
9 This is useful for testing:
11 * Do your project's objects really serialize/unserialize correctly in all cases?
12 * Is there an incorrectly formatted object that will cause your project to panic?
14 Import with ```import "github.com/google/gofuzz"```
16 You can use it on single variables:
20 f.Fuzz(&myInt) // myInt gets a random value.
23 You can use it on maps:
25 f := fuzz.New().NilChance(0).NumElements(1, 1)
26 var myMap map[ComplexKeyType]string
27 f.Fuzz(&myMap) // myMap will have exactly one element.
30 Customize the chance of getting a nil pointer:
32 f := fuzz.New().NilChance(.5)
33 var fancyStruct struct {
36 f.Fuzz(&fancyStruct) // About half the pointers should be set.
39 You can even customize the randomization completely if needed:
52 f := fuzz.New().NilChance(0).Funcs(
53 func(e *MyInfo, c fuzz.Continue) {
66 f.Fuzz(&myObject) // Type will correspond to whether A or B info is set.
69 See more examples in ```example_test.go```.