Skip to content
forked from google/gofuzz

Fuzz testing for Go Applications (Used By Quarantine)

Notifications You must be signed in to change notification settings

benchlab/gogreenrun

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gogreenrun

GoGreenRun is a library for populating go objects with random values.

<<<<<<< HEAD GoDoc Travis

=======

9aa5c6257e94c42563588536734f491aee9f2003 This is useful for testing:

  • Do your project's objects really serialize/unserialize correctly in all cases?
  • Is there an incorrectly formatted object that will cause your project to panic?

Import with import "github.com/benchlab/gogreenrun"

You can use it on single variables:

f := greenrun.New()
var myInt int
f.GreenRun(&myInt)

You can use it on maps:

f := greenrun.New().NilChance(0).NumElements(1, 1)
var myMap map[ComplexKeyType]string
f.GreenRun(&myMap)

Customize the chance of getting a nil pointer:

f := greenrun.New().NilChance(.5)
var fancyStruct struct {
  A, B, C, D *string
}
f.GreenRun(&fancyStruct) 

You can even customize the randomization completely if needed:

type MyEnum string
const (
        A MyEnum = "A"
        B MyEnum = "B"
)
type MyInfo struct {
        Type MyEnum
        AInfo *string
        BInfo *string
}

f := greenrun.New().NilChance(0).Funcs(
        func(e *MyInfo, c greenrun.Continue) {
                switch c.Intn(2) {
                case 0:
                        e.Type = A
                        c.GreenRun(&e.AInfo)
                case 1:
                        e.Type = B
                        c.GreenRun(&e.BInfo)
                }
        },
)

var myObject MyInfo
f.GreenRun(&myObject)

See more examples in example_test.go.

Happy testing!

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%